-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathColorCells.ts
More file actions
27 lines (24 loc) · 910 Bytes
/
ColorCells.ts
File metadata and controls
27 lines (24 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* This sample demonstartes how to iterate over a selected range and set cell property. It colors each cell within the selected range with a random color.
*/
function main(workbook: ExcelScript.Workbook) {
const syncStart = new Date().getTime();
// Get selected range
const range = workbook.getSelectedRange();
const rows = range.getRowCount();
const cols = range.getColumnCount();
console.log("Start");
// Color each cell with random color
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
range
.getCell(row, col)
.getFormat()
.getFill()
.setColor(`#${Math.random().toString(16).substr(-6)}`);
}
}
console.log("End");
const syncEnd = new Date().getTime();
console.log("Completed, took: " + (syncEnd - syncStart) / 1000 + " Sec");
}