-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathCopyTables.ts
More file actions
24 lines (21 loc) · 921 Bytes
/
Copy pathCopyTables.ts
File metadata and controls
24 lines (21 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function main(workbook: ExcelScript.Workbook) {
workbook.getWorksheet('Combined')?.delete();
const newSheet = workbook.addWorksheet('Combined');
const tables = workbook.getTables();
const headerValues = tables[0].getHeaderRowRange().getTexts();
console.log(headerValues);
const targetRange = updateRange(newSheet, headerValues);
const combinedTable = newSheet.addTable(targetRange.getAddress(), true);
for (let table of tables) {
let dataValues = table.getRangeBetweenHeaderAndTotal().getTexts();
let rowCount = table.getRowCount();
if (rowCount > 0) {
combinedTable.addRows(-1, dataValues);
}
}
}
function updateRange(sheet: ExcelScript.Worksheet, data: string[][]): ExcelScript.Range {
const targetRange = sheet.getRange('A1').getResizedRange(data.length-1, data[0].length-1);
targetRange.setValues(data);
return targetRange;
}