Skip to content

Commit de89c86

Browse files
author
Pravandan Chand
committed
adds synchronous custom function sample showing how to read a cell value using @SupportSync
1 parent ee3dbf3 commit de89c86

5 files changed

Lines changed: 56 additions & 3 deletions

File tree

playlists-prod/excel.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,4 +1449,15 @@
14491449
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/99-just-for-fun/color-wheel.yaml
14501450
group: Just For Fun
14511451
api_set:
1452-
ExcelApi: '1.4'
1452+
ExcelApi: '1.4'
1453+
- id: excel-custom-functions-sync
1454+
name: Synchronous custom function
1455+
fileName: synchronous-function.yaml
1456+
description: >-
1457+
A synchronous custom function that reads a cell value in tandem with Excel's
1458+
calculation process.
1459+
rawUrl: >-
1460+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/preview-apis/synchronous-function.yaml
1461+
group: Preview APIs
1462+
api_set:
1463+
CustomFunctionsRuntime: 1.5

playlists/excel.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,3 +1450,14 @@
14501450
group: Just For Fun
14511451
api_set:
14521452
ExcelApi: '1.4'
1453+
- id: excel-custom-functions-sync
1454+
name: Synchronous custom function
1455+
fileName: synchronous-function.yaml
1456+
description: >-
1457+
A synchronous custom function that reads a cell value in tandem with Excel's
1458+
calculation process.
1459+
rawUrl: >-
1460+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/preview-apis/synchronous-function.yaml
1461+
group: Preview APIs
1462+
api_set:
1463+
CustomFunctionsRuntime: 1.5
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
order: 9
2+
id: excel-custom-functions-sync
3+
name: Synchronous custom function
4+
description: A synchronous custom function that reads a cell value in tandem with Excel's calculation process.
5+
host: EXCEL
6+
api_set:
7+
CustomFunctionsRuntime: 1.5
8+
script:
9+
content: |
10+
/**
11+
* Gets the value of a cell, evaluated synchronously with Excel's calculation.
12+
* @customfunction
13+
* @supportSync
14+
* @param {string} address The cell address, e.g. "A1"
15+
* @param {CustomFunctions.Invocation} invocation
16+
* @returns {Promise<any>} The cell value.
17+
*/
18+
async function getCellValue(address: string, invocation: CustomFunctions.Invocation): Promise<any> {
19+
const context = new Excel.RequestContext();
20+
context.setInvocation(invocation as any);
21+
const range = context.workbook.worksheets.getActiveWorksheet().getRange(address);
22+
range.load("values");
23+
await context.sync();
24+
return range.values[0][0];
25+
}
26+
language: typescript
27+
libraries: |
28+
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
29+
https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/office-js-preview/index.d.ts

view-prod/excel.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,6 @@
149149
"excel-just-for-fun-gradient": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/99-just-for-fun/gradient.yaml",
150150
"excel-just-for-fun-path-finder-game": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/99-just-for-fun/path-finder-game.yaml",
151151
"excel-just-for-fun-tetrominos": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/99-just-for-fun/tetrominos.yaml",
152-
"excel-just-for-fun-color-wheel": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/99-just-for-fun/color-wheel.yaml"
152+
"excel-just-for-fun-color-wheel": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/99-just-for-fun/color-wheel.yaml",
153+
"excel-custom-functions-sync": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/preview-apis/synchronous-function.yaml"
153154
}

view/excel.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,6 @@
149149
"excel-just-for-fun-gradient": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/99-just-for-fun/gradient.yaml",
150150
"excel-just-for-fun-path-finder-game": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/99-just-for-fun/path-finder-game.yaml",
151151
"excel-just-for-fun-tetrominos": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/99-just-for-fun/tetrominos.yaml",
152-
"excel-just-for-fun-color-wheel": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/99-just-for-fun/color-wheel.yaml"
152+
"excel-just-for-fun-color-wheel": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/99-just-for-fun/color-wheel.yaml",
153+
"excel-custom-functions-sync": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/preview-apis/synchronous-function.yaml"
153154
}

0 commit comments

Comments
 (0)