fix(Google Sheets Node): Fix for append operation if no empty rows in sheet

This commit is contained in:
Michael Kret
2022-12-01 10:39:03 +02:00
committed by GitHub
parent 6d4e959884
commit 741c7da8b1
8 changed files with 211 additions and 171 deletions

View File

@@ -187,6 +187,43 @@ export class GoogleSheet {
return response;
}
async appendEmptyRowsOrColumns(sheetId: string, rowsToAdd = 1, columnsToAdd = 1) {
const requests: IDataObject[] = [];
if (rowsToAdd > 0) {
requests.push({
appendDimension: {
sheetId,
dimension: 'ROWS',
length: rowsToAdd,
},
});
}
if (columnsToAdd > 0) {
requests.push({
appendDimension: {
sheetId,
dimension: 'COLUMNS',
length: columnsToAdd,
},
});
}
if (requests.length === 0) {
throw new Error('Must specify at least one column or row to add');
}
const response = await apiRequest.call(
this.executeFunctions,
'POST',
`/v4/spreadsheets/${this.id}:batchUpdate`,
{ requests },
);
return response;
}
/**
* Appends the cell values
*/