node-google-spreadsheet
node-google-spreadsheet copied to clipboard
Saving a column to all empty values throws a TypeError error
I am trying to save a row with all empty records.
However, the save()
function in GoogleSpreadsheetRow.js has this at the very end:
this._rawData = response.data.updatedData.values[0];
Since there are no values, response.data.updatedData.values
is undefined, and Javascript throws a TypeError.
BTW, I am emptying a row as I am dealing with a data disaster... I thought rows were deleted "by ID". I have a script that deletes rows that satisfied a specific condition. But, as I deleted a row at the top, the NEXT row that was deleted was the wrong one (!) since the rows had "shifted up". Am I doing something wrong? Or maybe is it worthwhile having a note on the documentation saying that after deleting a row, it's best to reload the sheet?
I'm not sure Google's API will be very happy about trying to save a row with all empty values. I think if you set things to empty strings, it should be OK.
Re: deleting rows - updating the local cache after deleting rows is not something I've dealt with. Unfortunately Google's API doesn't give me row IDs to work with, so it's a bit tricky. Definitely could use some clarification in the docs!!
@theoephraim saving all empty strings doesn't work either, same issue. I had to do this to work around it:
try{
await row.save();
} catch (e) {
//expected error when we save an empty row
}
@lilsweetkara - the new version I just released should do better handling of deleting rows to keep row numbers in sync as others are deleted.
I'll have to do some digging to see if I can get saving a row of empty values to work.