-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathAddRowAtEnd.ts
More file actions
22 lines (20 loc) · 766 Bytes
/
AddRowAtEnd.ts
File metadata and controls
22 lines (20 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getWorksheet('Sheet5');
const data = ['2016', 'Bikes', 'Seats', '1500', .05];
addRow(sheet, data);
return;
}
function addRow(sheet: ExcelScript.Worksheet, data: (string | number | boolean)[]): void {
const usedRange = sheet.getUsedRange();
let startCell: ExcelScript.Range;
// IF the sheet is empty, then use A1 as starting cell for update
if (usedRange) {
startCell = usedRange.getLastRow().getCell(0, 0).getOffsetRange(1, 0);
} else {
startCell = sheet.getRange('A1');
}
console.log(startCell.getAddress());
const targetRange = startCell.getResizedRange(0, data.length - 1);
targetRange.setValues([data]);
return;
}