node-google-spreadsheet icon indicating copy to clipboard operation
node-google-spreadsheet copied to clipboard

Passing Empty String as value causes addRow to overwrite row 1

Open jwhiteaei opened this issue 3 years ago • 4 comments

I have a spreadsheet with a protected first row (1:1 range), which contains the header values I reference in dot notation when adding rows to my spreadsheet. I discovered today that passing the empty string will cause the function to attempt to overwrite the first row instead of appending the data to the last row. Luckily, it returned an error because it is a protected range. For example, the following would cause the issue:

    await sheet.addRow({ date: "today", number: "5", customer: "" });

While the below would append to the last spreadsheet row, as expected:

    await sheet.addRow({ date: "today", number: "5", customer: "Bob" });

I am working around the empty string values in my code, by converting them to null, which still allows the function to append, while also having (possibly) blank cells:

    await sheet.addRow({ date: "today", number: "5", customer: null });

No action needed, just wanted to post this as a possible improvement idea, or to be of help if someone else has the same problem.

jwhiteaei avatar Jan 26 '21 19:01 jwhiteaei

Very odd - I'll have to check that out! It's definitely not expected behaviour.

theoephraim avatar Jan 28 '21 00:01 theoephraim

I am having the same issue, so I really appreciate you writing this up @jwhiteaei so I can do the workaround!

cjbeattie avatar Dec 07 '21 07:12 cjbeattie

Scratch that. I'm definitely not passing in empty strings but every so often the first row is overwritten. I can't see any consistent pattern in the values as to why some work and some don't. Weird.

cjbeattie avatar Dec 07 '21 07:12 cjbeattie

@cjbeattie - if you can share a copy of your sheet with me ([email protected]) and a code example, I can try to take a look

theoephraim avatar Dec 09 '21 18:12 theoephraim

closing this - please send more details and reopen if you are still having issues.

theoephraim avatar Jun 26 '23 17:06 theoephraim