Reputation: 147
This script sends the data content of an html table to a Google Sheet.
But I now need it to append the data to the next available row.
I've used appendRow()
in many cases, but I'm not sure of the syntax in this particular case.
function pasteRequisicaoHtml(table) {
var ss = SpreadsheetApp.openById("1J_7GZ1C7pgHuRsdfsdfsdfsdf");
var sheet = ss.getSheetByName('Sheet5').getSheetId();
var req = {
requests: [
{
pasteData: {
html: true,
data: table,
coordinate: {
sheetId: sheet,
rowIndex: 2,
columnIndex: 0,
},
},
},
],
};
Sheets.Spreadsheets.batchUpdate(req, ss.getId());
}
Upvotes: 1
Views: 669
Reputation: 201388
If my understanding is correct, how about this answer?
getLastRow()
of Spreadsheet service. And please use the value retrieved by getLastRow()
to rowIndex
.When this is reflected to your script, it becomes as follows.
function pasteRequisicaoHtml(table) {
var ss = SpreadsheetApp.openById("1J_7GZ1C7pgHuRsdfsdfsdfsdf");
var sheet = ss.getSheetByName('Sheet5'); // Modified
var req = {
requests: [{
pasteData: {
html: true,
data: table,
coordinate: {
sheetId: sheet.getSheetId(), // Modified
rowIndex: sheet.getLastRow(), // Modified
columnIndex: 0,
},
},
}, ],
};
Sheets.Spreadsheets.batchUpdate(req, ss.getId());
}
In this sample script, the header row is deleted after the table is append. In this case, it supposes that the header row is one row.
function pasteRequisicaoHtml(table) {
var ss = SpreadsheetApp.openById("1J_7GZ1C7pgHuRsdfsdfsdfsdf");
var sheet = ss.getSheetByName('Sheet5'); // Modified
var lastRow = sheet.getLastRow(); // Added
var req = {
requests: [{
pasteData: {
html: true,
data: table,
coordinate: {
sheetId: sheet.getSheetId(), // Modified
rowIndex: lastRow, // Modified
columnIndex: 0,
},
},
}, ],
};
Sheets.Spreadsheets.batchUpdate(req, ss.getId());
sheet.deleteRow(lastRow + 1); // Added
}
Upvotes: 1