-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathUpdate2DRangeValues.ts
More file actions
31 lines (31 loc) · 1.38 KB
/
Update2DRangeValues.ts
File metadata and controls
31 lines (31 loc) · 1.38 KB
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
28
29
30
31
function main(workbook: ExcelScript.Workbook) {
const currentCell = workbook.getActiveCell();
let inputRange = computeTargetRange(currentCell, DATA);
// Set range values.
console.log(inputRange.getAddress());
inputRange.setValues(DATA);
// Call a helper function to place border around the range.
borderAround(inputRange);
}
/**
* A Helper function that computes the target range given the target range's starting cell and selected range.
*/
function computeTargetRange(targetCell: ExcelScript.Range, data: string[][]): ExcelScript.Range {
const targetRange = targetCell.getResizedRange(data.length - 1, data[0].length - 1);
return targetRange;
}
/**
* A Helper function that places a border around the range.
*/
function borderAround(range: ExcelScript.Range): void {
range.getFormat().getRangeBorder(ExcelScript.BorderIndex.edgeLeft).setStyle(ExcelScript.BorderLineStyle.dash);
range.getFormat().getRangeBorder(ExcelScript.BorderIndex.edgeRight).setStyle(ExcelScript.BorderLineStyle.dash);
range.getFormat().getRangeBorder(ExcelScript.BorderIndex.edgeTop).setStyle(ExcelScript.BorderLineStyle.dash);
range.getFormat().getRangeBorder(ExcelScript.BorderIndex.edgeBottom).setStyle(ExcelScript.BorderLineStyle.dash);
return;
}
// Values used for range setup.
const DATA = [
['Item', 'Bread', 'Donuts', 'Cookies', 'Cakes', 'Pies'],
['Amount', '2', '1.5', '4', '12', '26']
]