spreadsheet
spreadsheet copied to clipboard
Stop google converting strings to numbers (USER_ENTERED vs RAW)
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
I’m thinking a configuration setting in https://github.com/Iwark/spreadsheet/blob/v2/properties.go
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
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.
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.
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.
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!