Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zaddok opened this issue Jul 27, 2019 · 6 comments
Open

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

zaddok opened this issue Jul 27, 2019 · 6 comments

Comments

@zaddok
Copy link

zaddok commented Jul 27, 2019

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
Copy link
Author

zaddok commented Jul 27, 2019

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

@Iwark
Copy link
Owner

Iwark commented Jul 30, 2019

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
Copy link
Owner

Iwark commented Jul 30, 2019

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
Copy link

vertoforce commented Apr 25, 2020

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
Copy link

vertoforce commented Apr 25, 2020

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
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants