Iwark / spreadsheet

Google Go (golang) library for reading and writing spreadsheet files on Google Docs.
MIT License
382 stars 53 forks source link

Stop google converting strings to numbers (USER_ENTERED vs RAW) #40

Open zaddok opened 5 years ago

zaddok commented 5 years ago

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 commented 5 years ago

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

Iwark commented 5 years ago

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 commented 5 years ago

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.

vertoforce commented 4 years ago

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 commented 4 years ago

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.

MarErm27 commented 4 years ago

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!