Skip to content

Number-like strings Google Sheets append/setValue bug. #20

@Dmytro2V

Description

@Dmytro2V

<Sorry didn't done testing for my patch function... Have no so much interest for this way now, switching.
But still using Sheetquery.>

I've met a Google Sheets/Scripts bug both with sheet.appendRow() as well as range.setValue()
If we have a value like '01234' we will receive 1234 number. If we have a string like '22 34' we will receive number 2234.

Ways to prevent this:

  1. Set 'plain text' format on the column first. It works, but if you have automatic format, you will be down. Too risky.
  2. Add a ' symbol to set string. Not too well, as symbol also will be stored in the cell.
  3. Avoid such strings and use other delimiters... Not very beautiful and universal.
  4. There are range.setNumberFormat() and range.setNumberFormats() functions which can be used.

But there are still some issues:

  • we can set a string format for string values '@' easily, and it works well. Just sets cell format to string and thus putting string values unchanged. Even if we will change the format to 'automatic' afterwards, string will be still ok.
  • but there are no so universal formats for other types. For numbers and dates we have to set format explicitly, which is not good. Well, there possible is a null format as 'General', but it is undocumented.

So the summary is we cannot use .setNumberFormats() as there are no documented null formats, but we can check every value typeof and set string '@' format for string values with range.setNumberFormat().setValue()
I've implemented this in my 'patch' function as it already sets values cell-by-cell and it works fantastic :)

There are also smaller issues of this Google Scripts bug - sometimes using small numbers can lead to transform them to data. But this probably is not so big problem as this influences only a view, not real data (dates on sheet are stored as numbers anyway).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions