-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemoveEventHandlerSample.yaml
105 lines (68 loc) · 2.39 KB
/
RemoveEventHandlerSample.yaml
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Remove Event's handle
description: Test remove Excel Events
author: Shanbo
host: EXCEL
api_set: {}
script:
content: |
$("#add").click(() => tryCatch(add));
$("#remove").click(() => tryCatch(remove));
var eventResult;
async function add() {
await Excel.run(async (ctx) => {
var sheetName = "Sheet1";
var worksheet = ctx.workbook.worksheets.getItem(sheetName);
eventResult = worksheet.onSelectionChanged.add(onSelectionChanged);
await ctx.sync();
OfficeHelpers.UI.notify("add event sucess");
});
function onSelectionChanged(args) {
console.log("selection changed " + args.address);
}
}
async function remove() {
if(!eventResult || !eventResult.context)
{
console.log("no added the handler");
return;
}
await Excel.run(eventResult.context, async (ctx) => {
eventResult.remove();
await ctx.sync() ;
OfficeHelpers.UI.notify("remove event sucess");
});
}
/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
}
catch (error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
}
}
language: typescript
template:
content: |
<button id="add" class="ms-Button">
<span class="ms-Button-label">add</span>
</button>
<button id="remove" class="ms-Button">
<span class="ms-Button-label">remove</span>
</button>
language: html
style:
content: "/* Your style goes here */\r\n"
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/beta/hosted/office.debug.js
https://appsforoffice.microsoft.com/lib/beta/hosted/office.d.ts
[email protected]/dist/css/fabric.min.css
[email protected]/dist/css/fabric.components.min.css
[email protected]/client/core.min.js
@types/core-js
@microsoft/[email protected]/dist/office.helpers.min.js
@microsoft/[email protected]/dist/office.helpers.d.ts
@types/jquery