spreadsheet icon indicating copy to clipboard operation
spreadsheet copied to clipboard

Stop google converting strings to numbers (USER_ENTERED vs RAW)

Open zaddok opened this issue 4 years ago • 6 comments

This library uses a very sensible USER_ENTERED default option for updating cells. There may be times (such as in my current project) where the ability to change this is useful. Currently the default is hardcoded:

func (s *Service) syncCells(sheet *Sheet) (err error) {
	path := fmt.Sprintf("/spreadsheets/%s/values:batchUpdate", sheet.Spreadsheet.ID)
	params := map[string]interface{}{
		"valueInputOption": "USER_ENTERED",
		"data":             make([]map[string]interface{}, 0, len(sheet.modifiedCells)),
	}

It is causing some problems for me (i.e an occasional string being represented as a number, which causes formatting and other minor issues)

Can we do a patch to allow this to be altered, what are your thoughts on making it adjustable?

https://developers.google.com/sheets/api/reference/rest/v4/ValueInputOption

zaddok avatar Jul 27 '19 22:07 zaddok

I’m thinking a configuration setting in https://github.com/Iwark/spreadsheet/blob/v2/properties.go

zaddok avatar Jul 27 '19 23:07 zaddok

Yeah, it'd be better to be configurable. I think having these consts and the global variable to store that with default value USER_ENTERED won't break any existing functions

InputValueOptionUnspecified
Raw
UserEntered

Iwark avatar Jul 30 '19 02:07 Iwark

Or if we want to put the config including future ones we'll create together, we can make an explicit config struct and have something like NewServiceWithConfig I'm not sure it'll be useful atm, though.

Iwark avatar Jul 30 '19 02:07 Iwark

Did this ever lead to a PR or anything? I'm looking for this feature also.

Also can't find that option to change in the current code.

vertoforce avatar Apr 25 '20 17:04 vertoforce

In case anybody else is facing this problem, I forked this and made this change and this change to support overriding the default cell type.

So you can set customType to a custom value to force the cell being inserted as a string or boolean, etc.

Check this spec on the google spreadsheet docs for more information.

vertoforce avatar Apr 25 '20 21:04 vertoforce

In case anybody else is facing this problem, I forked this and made this change and this change to support overriding the default cell type.

So you can set customType to a custom value to force the cell being inserted as a string or boolean, etc.

Check this spec on the google spreadsheet docs for more information.

thank you so much!

MarErm27 avatar Jul 13 '20 13:07 MarErm27