I really don't get how I can write new rows with the apiv4.
let's say I have a table with the columns ID, name, count, size.
The official nodejs example looks like this:
let values = [
[
// Cell values ...
],
// Additional rows ...
];
let resource = {
values,
};
this.sheetsService.spreadsheets.values.append({
spreadsheetId,
range,
valueInputOption,
resource,
}, (err, result) => {
if (err) {
// Handle error.
console.log(err);
} else {
console.log(`${result.updates.updatedCells} cells appended.`);
}
});
So for this to work I need the variables values, spreadsheetId, range and valueInputOption.
For value it says that the cell values go in there. Does this mean it must be filled with order from left to right? like with my example:
let values = [
[
"h7Bfhi87gBjh7fs9", //first the id
"Max", //then name
"20", //count
"500" //size
]
];
Would this be correct?
spreadsheetId do I already have.
For the last two variables I don't know what they mean.
First the range variable. For reading, you must give the function a range to read from, that is simple. But Why do I need a range if I want to append rows to the table?
Second, I have no clue what valueInputOption does.
tldr:
What values do I need to declare to the variables values, range and valueInputOptions if I want to append rows to a spreadsheet with google spreadsheet apiv4?
If you just want to append rows at the end, you can specify "Sheet1" (or whatever the name of the sheet your want to append to) for the range (cf https://developers.google.com/sheets/api/guides/values#appending_values).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With