tdrpa.tdworker 1.2.13.2__py312-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tdrpa/_tdxlwings/__init__.py +193 -0
- tdrpa/_tdxlwings/__pycache__/__init__.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/__init__.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/_win32patch.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/_win32patch.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/_xlwindows.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/_xlwindows.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/apps.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/apps.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/base_classes.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/base_classes.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/com_server.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/com_server.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/constants.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/constants.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/expansion.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/expansion.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/main.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/main.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/udfs.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/udfs.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/utils.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/utils.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/_win32patch.py +90 -0
- tdrpa/_tdxlwings/_xlmac.py +2240 -0
- tdrpa/_tdxlwings/_xlwindows.py +2518 -0
- tdrpa/_tdxlwings/addin/Dictionary.cls +474 -0
- tdrpa/_tdxlwings/addin/IWebAuthenticator.cls +71 -0
- tdrpa/_tdxlwings/addin/WebClient.cls +772 -0
- tdrpa/_tdxlwings/addin/WebHelpers.bas +3203 -0
- tdrpa/_tdxlwings/addin/WebRequest.cls +875 -0
- tdrpa/_tdxlwings/addin/WebResponse.cls +453 -0
- tdrpa/_tdxlwings/addin/xlwings.xlam +0 -0
- tdrpa/_tdxlwings/apps.py +35 -0
- tdrpa/_tdxlwings/base_classes.py +1092 -0
- tdrpa/_tdxlwings/cli.py +1306 -0
- tdrpa/_tdxlwings/com_server.py +385 -0
- tdrpa/_tdxlwings/constants.py +3080 -0
- tdrpa/_tdxlwings/conversion/__init__.py +103 -0
- tdrpa/_tdxlwings/conversion/framework.py +147 -0
- tdrpa/_tdxlwings/conversion/numpy_conv.py +34 -0
- tdrpa/_tdxlwings/conversion/pandas_conv.py +184 -0
- tdrpa/_tdxlwings/conversion/standard.py +321 -0
- tdrpa/_tdxlwings/expansion.py +83 -0
- tdrpa/_tdxlwings/ext/__init__.py +3 -0
- tdrpa/_tdxlwings/ext/sql.py +73 -0
- tdrpa/_tdxlwings/html/xlwings-alert.html +71 -0
- tdrpa/_tdxlwings/js/xlwings.js +577 -0
- tdrpa/_tdxlwings/js/xlwings.ts +729 -0
- tdrpa/_tdxlwings/mac_dict.py +6399 -0
- tdrpa/_tdxlwings/main.py +5205 -0
- tdrpa/_tdxlwings/mistune/__init__.py +63 -0
- tdrpa/_tdxlwings/mistune/block_parser.py +366 -0
- tdrpa/_tdxlwings/mistune/inline_parser.py +216 -0
- tdrpa/_tdxlwings/mistune/markdown.py +84 -0
- tdrpa/_tdxlwings/mistune/renderers.py +220 -0
- tdrpa/_tdxlwings/mistune/scanner.py +121 -0
- tdrpa/_tdxlwings/mistune/util.py +41 -0
- tdrpa/_tdxlwings/pro/__init__.py +40 -0
- tdrpa/_tdxlwings/pro/_xlcalamine.py +536 -0
- tdrpa/_tdxlwings/pro/_xlofficejs.py +146 -0
- tdrpa/_tdxlwings/pro/_xlremote.py +1293 -0
- tdrpa/_tdxlwings/pro/custom_functions_code.js +150 -0
- tdrpa/_tdxlwings/pro/embedded_code.py +60 -0
- tdrpa/_tdxlwings/pro/udfs_officejs.py +549 -0
- tdrpa/_tdxlwings/pro/utils.py +199 -0
- tdrpa/_tdxlwings/quickstart.xlsm +0 -0
- tdrpa/_tdxlwings/quickstart_addin.xlam +0 -0
- tdrpa/_tdxlwings/quickstart_addin_ribbon.xlam +0 -0
- tdrpa/_tdxlwings/quickstart_fastapi/main.py +47 -0
- tdrpa/_tdxlwings/quickstart_fastapi/requirements.txt +3 -0
- tdrpa/_tdxlwings/quickstart_standalone.xlsm +0 -0
- tdrpa/_tdxlwings/reports.py +12 -0
- tdrpa/_tdxlwings/rest/__init__.py +1 -0
- tdrpa/_tdxlwings/rest/api.py +368 -0
- tdrpa/_tdxlwings/rest/serializers.py +103 -0
- tdrpa/_tdxlwings/server.py +14 -0
- tdrpa/_tdxlwings/udfs.py +775 -0
- tdrpa/_tdxlwings/utils.py +777 -0
- tdrpa/_tdxlwings/xlwings-0.31.6.applescript +30 -0
- tdrpa/_tdxlwings/xlwings.bas +2061 -0
- tdrpa/_tdxlwings/xlwings_custom_addin.bas +2042 -0
- tdrpa/_tdxlwings/xlwingslib.cp38-win_amd64.pyd +0 -0
- tdrpa/tdworker/__init__.pyi +12 -0
- tdrpa/tdworker/_clip.pyi +50 -0
- tdrpa/tdworker/_excel.pyi +743 -0
- tdrpa/tdworker/_file.pyi +77 -0
- tdrpa/tdworker/_img.pyi +226 -0
- tdrpa/tdworker/_network.pyi +94 -0
- tdrpa/tdworker/_os.pyi +47 -0
- tdrpa/tdworker/_sp.pyi +21 -0
- tdrpa/tdworker/_w.pyi +129 -0
- tdrpa/tdworker/_web.pyi +995 -0
- tdrpa/tdworker/_winE.pyi +228 -0
- tdrpa/tdworker/_winK.pyi +74 -0
- tdrpa/tdworker/_winM.pyi +117 -0
- tdrpa/tdworker.cp312-win_amd64.pyd +0 -0
- tdrpa_tdworker-1.2.13.2.dist-info/METADATA +38 -0
- tdrpa_tdworker-1.2.13.2.dist-info/RECORD +101 -0
- tdrpa_tdworker-1.2.13.2.dist-info/WHEEL +5 -0
- tdrpa_tdworker-1.2.13.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,729 @@
|
|
1
|
+
async function main(workbook: ExcelScript.Workbook) {
|
2
|
+
await runPython(workbook, "url", { auth: "DEVELOPMENT" });
|
3
|
+
}
|
4
|
+
|
5
|
+
/**
|
6
|
+
* xlwings for Microsoft Office Scripts
|
7
|
+
* Copyright (C) 2014 - present, Zoomer Analytics GmbH.
|
8
|
+
* All rights reserved.
|
9
|
+
*
|
10
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
11
|
+
* are permitted provided that the following conditions are met:
|
12
|
+
*
|
13
|
+
* * Redistributions of source code must retain the above copyright notice, this
|
14
|
+
* list of conditions and the following disclaimer.
|
15
|
+
*
|
16
|
+
* * Redistributions in binary form must reproduce the above copyright notice, this
|
17
|
+
* list of conditions and the following disclaimer in the documentation and/or
|
18
|
+
* other materials provided with the distribution.
|
19
|
+
*
|
20
|
+
* * Neither the name of the copyright holder nor the names of its
|
21
|
+
* contributors may be used to endorse or promote products derived from
|
22
|
+
* this software without specific prior written permission.
|
23
|
+
*
|
24
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
25
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
26
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
27
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
28
|
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
29
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
30
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
31
|
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
32
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
33
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
globalThis.callbacks = {};
|
37
|
+
async function runPython(
|
38
|
+
workbook: ExcelScript.Workbook,
|
39
|
+
url = "",
|
40
|
+
{
|
41
|
+
auth = "",
|
42
|
+
apiKey = "",
|
43
|
+
include = "",
|
44
|
+
exclude = "",
|
45
|
+
headers = {},
|
46
|
+
}: Options = {}
|
47
|
+
): Promise<void> {
|
48
|
+
const version = "0.31.6";
|
49
|
+
const sheets = workbook.getWorksheets();
|
50
|
+
// Config
|
51
|
+
let configSheet = workbook.getWorksheet("xlwings.conf");
|
52
|
+
let config = {};
|
53
|
+
if (configSheet) {
|
54
|
+
// @ts-ignore
|
55
|
+
const configValues = workbook
|
56
|
+
.getWorksheet("xlwings.conf")
|
57
|
+
.getRange("A1")
|
58
|
+
.getSurroundingRegion()
|
59
|
+
.getValues();
|
60
|
+
configValues.forEach((el) => (config[el[0].toString()] = el[1].toString()));
|
61
|
+
}
|
62
|
+
|
63
|
+
if (apiKey === "") {
|
64
|
+
apiKey = config["API_KEY"] || "";
|
65
|
+
}
|
66
|
+
if (auth === "") {
|
67
|
+
auth = config["AUTH"] || "";
|
68
|
+
}
|
69
|
+
|
70
|
+
if (include === "") {
|
71
|
+
include = config["INCLUDE"] || "";
|
72
|
+
}
|
73
|
+
let includeArray: string[] = [];
|
74
|
+
if (include !== "") {
|
75
|
+
includeArray = include.split(",").map((item) => item.trim());
|
76
|
+
}
|
77
|
+
|
78
|
+
if (exclude === "") {
|
79
|
+
exclude = config["EXCLUDE"] || "";
|
80
|
+
}
|
81
|
+
let excludeArray: string[] = [];
|
82
|
+
if (exclude !== "") {
|
83
|
+
excludeArray = exclude.split(",").map((item) => item.trim());
|
84
|
+
}
|
85
|
+
if (includeArray.length > 0 && excludeArray.length > 0) {
|
86
|
+
throw "Either use 'include' or 'exclude', but not both!";
|
87
|
+
}
|
88
|
+
if (includeArray.length > 0) {
|
89
|
+
sheets.forEach((sheet) => {
|
90
|
+
if (!includeArray.includes(sheet.getName())) {
|
91
|
+
excludeArray.push(sheet.getName());
|
92
|
+
}
|
93
|
+
});
|
94
|
+
}
|
95
|
+
|
96
|
+
if (Object.keys(headers).length === 0) {
|
97
|
+
for (const property in config) {
|
98
|
+
if (property.toLowerCase().startsWith("header_")) {
|
99
|
+
headers[property.substring(7)] = config[property];
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
// Deprecated: replaced by "auth"
|
104
|
+
if (!("Authorization" in headers) && apiKey.length > 0) {
|
105
|
+
headers["Authorization"] = apiKey;
|
106
|
+
}
|
107
|
+
if (!("Authorization" in headers) && auth.length > 0) {
|
108
|
+
headers["Authorization"] = auth;
|
109
|
+
}
|
110
|
+
|
111
|
+
// Standard headers
|
112
|
+
headers["Content-Type"] = "application/json";
|
113
|
+
|
114
|
+
// Request payload
|
115
|
+
let payload: {} = {};
|
116
|
+
payload["client"] = "Microsoft Office Scripts";
|
117
|
+
payload["version"] = version;
|
118
|
+
let selection: string | null | undefined;
|
119
|
+
try {
|
120
|
+
selection = workbook.getSelectedRange().getAddress().split("!").pop();
|
121
|
+
} catch (error) {
|
122
|
+
selection = null;
|
123
|
+
}
|
124
|
+
payload["book"] = {
|
125
|
+
name: workbook.getName(),
|
126
|
+
active_sheet_index: workbook.getActiveWorksheet().getPosition(),
|
127
|
+
selection: selection,
|
128
|
+
};
|
129
|
+
|
130
|
+
// Names (book scope only)
|
131
|
+
let names: Names[] = [];
|
132
|
+
workbook.getNames().forEach((namedItem, ix) => {
|
133
|
+
// Currently filtering to named ranges
|
134
|
+
let itemType: ExcelScript.NamedItemType = namedItem.getType();
|
135
|
+
if (itemType === ExcelScript.NamedItemType.range) {
|
136
|
+
names.push({
|
137
|
+
name: namedItem.getName(),
|
138
|
+
sheet_index: namedItem.getRange().getWorksheet().getPosition(),
|
139
|
+
address: namedItem.getRange().getAddress().split("!").pop(),
|
140
|
+
scope_sheet_name: null,
|
141
|
+
scope_sheet_index: null,
|
142
|
+
book_scope:
|
143
|
+
namedItem.getScope() === ExcelScript.NamedItemScope.workbook,
|
144
|
+
});
|
145
|
+
}
|
146
|
+
});
|
147
|
+
payload["names"] = names;
|
148
|
+
|
149
|
+
payload["sheets"] = [];
|
150
|
+
let lastCellCol: number;
|
151
|
+
let lastCellRow: number;
|
152
|
+
let values: (string | number | boolean)[][] = [[]];
|
153
|
+
let categories: ExcelScript.NumberFormatCategory[][];
|
154
|
+
sheets.forEach((sheet) => {
|
155
|
+
let isSheetIncluded = !excludeArray.includes(sheet.getName());
|
156
|
+
if (sheet.getUsedRange() !== undefined) {
|
157
|
+
let lastCell = sheet.getUsedRange().getLastCell();
|
158
|
+
lastCellCol = lastCell.getColumnIndex();
|
159
|
+
lastCellRow = lastCell.getRowIndex();
|
160
|
+
} else {
|
161
|
+
lastCellCol = 0;
|
162
|
+
lastCellRow = 0;
|
163
|
+
}
|
164
|
+
|
165
|
+
// Names (sheet scope)
|
166
|
+
let namesSheetScope: Names[] = [];
|
167
|
+
sheet.getNames().forEach((namedItem, ix) => {
|
168
|
+
// Currently filtering to named ranges
|
169
|
+
let itemType: ExcelScript.NamedItemType = namedItem.getType();
|
170
|
+
if (itemType === ExcelScript.NamedItemType.range) {
|
171
|
+
namesSheetScope.push({
|
172
|
+
name: namedItem.getName(),
|
173
|
+
sheet_index: namedItem.getRange().getWorksheet().getPosition(),
|
174
|
+
address: namedItem.getRange().getAddress().split("!").pop(),
|
175
|
+
scope_sheet_name: namedItem.getWorksheet().getName(),
|
176
|
+
scope_sheet_index: namedItem.getWorksheet().getPosition(),
|
177
|
+
book_scope: false,
|
178
|
+
});
|
179
|
+
}
|
180
|
+
});
|
181
|
+
|
182
|
+
// Add sheet scoped names to book scoped names
|
183
|
+
payload["names"] = payload["names"].concat(namesSheetScope);
|
184
|
+
|
185
|
+
// values
|
186
|
+
if (isSheetIncluded) {
|
187
|
+
let range = sheet.getRangeByIndexes(
|
188
|
+
0,
|
189
|
+
0,
|
190
|
+
lastCellRow + 1,
|
191
|
+
lastCellCol + 1
|
192
|
+
);
|
193
|
+
values = range.getValues();
|
194
|
+
categories = range.getNumberFormatCategories();
|
195
|
+
// Handle dates
|
196
|
+
values.forEach(
|
197
|
+
(valueRow: (string | number | boolean)[], rowIndex: number) => {
|
198
|
+
const categoryRow = categories[rowIndex];
|
199
|
+
valueRow.forEach((value, colIndex: number) => {
|
200
|
+
const category = categoryRow[colIndex];
|
201
|
+
if (
|
202
|
+
(category.toString() === "Date" ||
|
203
|
+
category.toString() === "Time") &&
|
204
|
+
typeof value === "number"
|
205
|
+
) {
|
206
|
+
values[rowIndex][colIndex] = new Date(
|
207
|
+
Math.round((value - 25569) * 86400 * 1000)
|
208
|
+
).toISOString();
|
209
|
+
}
|
210
|
+
});
|
211
|
+
}
|
212
|
+
);
|
213
|
+
}
|
214
|
+
// Tables
|
215
|
+
let tables: Tables[] = [];
|
216
|
+
if (isSheetIncluded) {
|
217
|
+
for (let table of sheet.getTables()) {
|
218
|
+
tables.push({
|
219
|
+
name: table.getName(),
|
220
|
+
range_address: table.getRange().getAddress().split("!").pop(),
|
221
|
+
header_row_range_address: table.getShowHeaders()
|
222
|
+
? table.getHeaderRowRange().getAddress().split("!").pop()
|
223
|
+
: null,
|
224
|
+
data_body_range_address: table
|
225
|
+
.getRangeBetweenHeaderAndTotal()
|
226
|
+
.getAddress()
|
227
|
+
.split("!")
|
228
|
+
.pop(),
|
229
|
+
total_row_range_address: table.getShowTotals()
|
230
|
+
? table.getTotalRowRange().getAddress().split("!").pop()
|
231
|
+
: null,
|
232
|
+
show_headers: table.getShowHeaders(),
|
233
|
+
show_totals: table.getShowTotals(),
|
234
|
+
table_style: table.getPredefinedTableStyle(),
|
235
|
+
show_autofilter: table.getShowFilterButton(),
|
236
|
+
});
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
240
|
+
// Pictures
|
241
|
+
let pictures: Pictures[] = [];
|
242
|
+
if (isSheetIncluded) {
|
243
|
+
for (let shape of sheet.getShapes())
|
244
|
+
if (shape.getType() === ExcelScript.ShapeType.image) {
|
245
|
+
pictures.push({
|
246
|
+
name: shape.getName(),
|
247
|
+
width: shape.getWidth(),
|
248
|
+
height: shape.getHeight(),
|
249
|
+
});
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
payload["sheets"].push({
|
254
|
+
name: sheet.getName(),
|
255
|
+
values: values,
|
256
|
+
pictures: pictures,
|
257
|
+
tables: tables,
|
258
|
+
});
|
259
|
+
});
|
260
|
+
|
261
|
+
// console.log(payload);
|
262
|
+
|
263
|
+
// API call
|
264
|
+
let response = await fetch(url, {
|
265
|
+
method: "POST",
|
266
|
+
headers: headers,
|
267
|
+
body: JSON.stringify(payload),
|
268
|
+
});
|
269
|
+
|
270
|
+
// Parse JSON response
|
271
|
+
let rawData: { actions: Action[] };
|
272
|
+
if (response.status !== 200) {
|
273
|
+
throw await response.text();
|
274
|
+
} else {
|
275
|
+
rawData = await response.json();
|
276
|
+
}
|
277
|
+
|
278
|
+
// console.log(rawData);
|
279
|
+
|
280
|
+
// Run Functions
|
281
|
+
if (rawData !== null) {
|
282
|
+
const forceSync = ["sheet", "table", "copy", "picture", "name"];
|
283
|
+
rawData["actions"].forEach((action) => {
|
284
|
+
if (action.func === "addPicture") {
|
285
|
+
// addPicture doesn't manage to pull both top and left from anchorCell otherwise
|
286
|
+
addPicture(workbook, action);
|
287
|
+
} else if (action.func === "updatePicture") {
|
288
|
+
updatePicture(workbook, action);
|
289
|
+
} else {
|
290
|
+
globalThis.callbacks[action.func](workbook, action);
|
291
|
+
}
|
292
|
+
if (forceSync.some((el) => action.func.toLowerCase().includes(el))) {
|
293
|
+
console.log(); // Force sync
|
294
|
+
}
|
295
|
+
});
|
296
|
+
}
|
297
|
+
}
|
298
|
+
|
299
|
+
// Helpers
|
300
|
+
interface Options {
|
301
|
+
auth?: string;
|
302
|
+
apiKey?: string;
|
303
|
+
include?: string;
|
304
|
+
exclude?: string;
|
305
|
+
headers?: {};
|
306
|
+
}
|
307
|
+
|
308
|
+
interface Action {
|
309
|
+
func: string;
|
310
|
+
args: (string | number | boolean)[];
|
311
|
+
values: (string | number | boolean)[][];
|
312
|
+
sheet_position: number;
|
313
|
+
start_row: number;
|
314
|
+
start_column: number;
|
315
|
+
row_count: number;
|
316
|
+
column_count: number;
|
317
|
+
}
|
318
|
+
|
319
|
+
interface Names {
|
320
|
+
name: string;
|
321
|
+
sheet_index: number;
|
322
|
+
address: string | undefined;
|
323
|
+
scope_sheet_name: string | undefined | null;
|
324
|
+
scope_sheet_index: number | undefined | null;
|
325
|
+
book_scope: boolean;
|
326
|
+
}
|
327
|
+
|
328
|
+
interface Tables {
|
329
|
+
name: string;
|
330
|
+
range_address: string | undefined;
|
331
|
+
header_row_range_address: string | undefined | null;
|
332
|
+
data_body_range_address: string | undefined;
|
333
|
+
total_row_range_address: string | undefined | null;
|
334
|
+
show_headers: boolean;
|
335
|
+
show_totals: boolean;
|
336
|
+
table_style: string;
|
337
|
+
show_autofilter: boolean;
|
338
|
+
}
|
339
|
+
|
340
|
+
interface Pictures {
|
341
|
+
name: string;
|
342
|
+
height: number;
|
343
|
+
width: number;
|
344
|
+
}
|
345
|
+
|
346
|
+
function getRange(workbook: ExcelScript.Workbook, action: Action) {
|
347
|
+
return workbook
|
348
|
+
.getWorksheets()
|
349
|
+
[action.sheet_position].getRangeByIndexes(
|
350
|
+
action.start_row,
|
351
|
+
action.start_column,
|
352
|
+
action.row_count,
|
353
|
+
action.column_count
|
354
|
+
);
|
355
|
+
}
|
356
|
+
|
357
|
+
function getShapeByType(
|
358
|
+
workbook: ExcelScript.Workbook,
|
359
|
+
sheetPosition: number,
|
360
|
+
shapeIndex: number,
|
361
|
+
shapeType: ExcelScript.ShapeType
|
362
|
+
) {
|
363
|
+
const myshapes = workbook
|
364
|
+
.getWorksheets()
|
365
|
+
[sheetPosition].getShapes()
|
366
|
+
.filter((shape: ExcelScript.Shape) => shape.getType() === shapeType);
|
367
|
+
return myshapes[shapeIndex];
|
368
|
+
}
|
369
|
+
|
370
|
+
function registerCallback(callback: Function) {
|
371
|
+
globalThis.callbacks[callback.name] = callback;
|
372
|
+
}
|
373
|
+
|
374
|
+
// Callbacks
|
375
|
+
function setValues(workbook: ExcelScript.Workbook, action: Action) {
|
376
|
+
// Handle DateTime (TODO: backend should deliver indices with datetime obj)
|
377
|
+
let dt: Date;
|
378
|
+
let dtString: string;
|
379
|
+
action.values.forEach((valueRow, rowIndex) => {
|
380
|
+
valueRow.forEach((value: string | number | boolean, colIndex) => {
|
381
|
+
if (
|
382
|
+
typeof value === "string" &&
|
383
|
+
value.length > 18 &&
|
384
|
+
value.includes("T")
|
385
|
+
) {
|
386
|
+
dt = new Date(Date.parse(value));
|
387
|
+
dtString = dt.toLocaleDateString();
|
388
|
+
if (dtString !== "Invalid Date") {
|
389
|
+
if (
|
390
|
+
dt.getHours() +
|
391
|
+
dt.getMinutes() +
|
392
|
+
dt.getSeconds() +
|
393
|
+
dt.getMilliseconds() !==
|
394
|
+
0
|
395
|
+
) {
|
396
|
+
dtString += " " + dt.toLocaleTimeString();
|
397
|
+
}
|
398
|
+
action.values[rowIndex][colIndex] = dtString;
|
399
|
+
}
|
400
|
+
}
|
401
|
+
});
|
402
|
+
});
|
403
|
+
getRange(workbook, action).setValues(action.values);
|
404
|
+
}
|
405
|
+
registerCallback(setValues);
|
406
|
+
|
407
|
+
function rangeClearContents(workbook: ExcelScript.Workbook, action: Action) {
|
408
|
+
getRange(workbook, action).clear(ExcelScript.ClearApplyTo.contents);
|
409
|
+
}
|
410
|
+
registerCallback(rangeClearContents);
|
411
|
+
|
412
|
+
function rangeClearFormats(workbook: ExcelScript.Workbook, action: Action) {
|
413
|
+
getRange(workbook, action).clear(ExcelScript.ClearApplyTo.formats);
|
414
|
+
}
|
415
|
+
registerCallback(rangeClearFormats);
|
416
|
+
|
417
|
+
function rangeClear(workbook: ExcelScript.Workbook, action: Action) {
|
418
|
+
getRange(workbook, action).clear();
|
419
|
+
}
|
420
|
+
registerCallback(rangeClear);
|
421
|
+
|
422
|
+
function addSheet(workbook: ExcelScript.Workbook, action: Action) {
|
423
|
+
let sheet: ExcelScript.Worksheet;
|
424
|
+
if (action.args[1] !== null) {
|
425
|
+
sheet = workbook.addWorksheet(action.args[1].toString());
|
426
|
+
} else {
|
427
|
+
sheet = workbook.addWorksheet();
|
428
|
+
}
|
429
|
+
sheet.setPosition(parseInt(action.args[0].toString()));
|
430
|
+
}
|
431
|
+
registerCallback(addSheet);
|
432
|
+
|
433
|
+
function setSheetName(workbook: ExcelScript.Workbook, action: Action) {
|
434
|
+
workbook
|
435
|
+
.getWorksheets()
|
436
|
+
[action.sheet_position].setName(action.args[0].toString());
|
437
|
+
}
|
438
|
+
registerCallback(setSheetName);
|
439
|
+
|
440
|
+
function setAutofit(workbook: ExcelScript.Workbook, action: Action) {
|
441
|
+
if (action.args[0] === "columns") {
|
442
|
+
getRange(workbook, action).getFormat().autofitColumns();
|
443
|
+
} else {
|
444
|
+
getRange(workbook, action).getFormat().autofitRows();
|
445
|
+
}
|
446
|
+
}
|
447
|
+
registerCallback(setAutofit);
|
448
|
+
|
449
|
+
function setRangeColor(workbook: ExcelScript.Workbook, action: Action) {
|
450
|
+
getRange(workbook, action)
|
451
|
+
.getFormat()
|
452
|
+
.getFill()
|
453
|
+
.setColor(action.args[0].toString());
|
454
|
+
}
|
455
|
+
registerCallback(setRangeColor);
|
456
|
+
|
457
|
+
function activateSheet(workbook: ExcelScript.Workbook, action: Action) {
|
458
|
+
workbook.getWorksheets()[parseInt(action.args[0].toString())].activate();
|
459
|
+
}
|
460
|
+
registerCallback(activateSheet);
|
461
|
+
|
462
|
+
function addHyperlink(workbook: ExcelScript.Workbook, action: Action) {
|
463
|
+
getRange(workbook, action).setHyperlink({
|
464
|
+
address: action.args[0].toString(),
|
465
|
+
textToDisplay: action.args[1].toString(),
|
466
|
+
screenTip: action.args[2].toString(),
|
467
|
+
});
|
468
|
+
}
|
469
|
+
registerCallback(addHyperlink);
|
470
|
+
|
471
|
+
function setNumberFormat(workbook: ExcelScript.Workbook, action: Action) {
|
472
|
+
getRange(workbook, action).setNumberFormat(action.args[0].toString());
|
473
|
+
}
|
474
|
+
registerCallback(setNumberFormat);
|
475
|
+
|
476
|
+
function setPictureName(workbook: ExcelScript.Workbook, action: Action) {
|
477
|
+
const myshape = getShapeByType(
|
478
|
+
workbook,
|
479
|
+
action.sheet_position,
|
480
|
+
Number(action.args[0]),
|
481
|
+
ExcelScript.ShapeType.image
|
482
|
+
);
|
483
|
+
myshape.setName(action.args[1].toString());
|
484
|
+
}
|
485
|
+
registerCallback(setPictureName);
|
486
|
+
|
487
|
+
function setPictureHeight(workbook: ExcelScript.Workbook, action: Action) {
|
488
|
+
const myshape = getShapeByType(
|
489
|
+
workbook,
|
490
|
+
action.sheet_position,
|
491
|
+
Number(action.args[0]),
|
492
|
+
ExcelScript.ShapeType.image
|
493
|
+
);
|
494
|
+
myshape.setHeight(Number(action.args[1]));
|
495
|
+
}
|
496
|
+
registerCallback(setPictureHeight);
|
497
|
+
|
498
|
+
function setPictureWidth(workbook: ExcelScript.Workbook, action: Action) {
|
499
|
+
const myshape = getShapeByType(
|
500
|
+
workbook,
|
501
|
+
action.sheet_position,
|
502
|
+
Number(action.args[0]),
|
503
|
+
ExcelScript.ShapeType.image
|
504
|
+
);
|
505
|
+
myshape.setWidth(Number(action.args[1]));
|
506
|
+
}
|
507
|
+
registerCallback(setPictureWidth);
|
508
|
+
|
509
|
+
function deletePicture(workbook: ExcelScript.Workbook, action: Action) {
|
510
|
+
const myshape = getShapeByType(
|
511
|
+
workbook,
|
512
|
+
action.sheet_position,
|
513
|
+
Number(action.args[0]),
|
514
|
+
ExcelScript.ShapeType.image
|
515
|
+
);
|
516
|
+
myshape.delete();
|
517
|
+
}
|
518
|
+
registerCallback(deletePicture);
|
519
|
+
|
520
|
+
function addPicture(workbook: ExcelScript.Workbook, action: Action) {
|
521
|
+
const imageBase64 = action["args"][0].toString();
|
522
|
+
const colIndex = Number(action["args"][1]);
|
523
|
+
const rowIndex = Number(action["args"][2]);
|
524
|
+
let left = Number(action["args"][3]);
|
525
|
+
let top = Number(action["args"][4]);
|
526
|
+
|
527
|
+
const sheet = workbook.getWorksheets()[action.sheet_position];
|
528
|
+
let anchorCell = sheet.getRangeByIndexes(rowIndex, colIndex, 1, 1);
|
529
|
+
left = Math.max(left, anchorCell.getLeft());
|
530
|
+
top = Math.max(top, anchorCell.getTop());
|
531
|
+
const image = sheet.addImage(imageBase64);
|
532
|
+
image.setLeft(left);
|
533
|
+
image.setTop(top);
|
534
|
+
}
|
535
|
+
registerCallback(addPicture);
|
536
|
+
|
537
|
+
function updatePicture(workbook: ExcelScript.Workbook, action: Action) {
|
538
|
+
const imageBase64 = action["args"][0].toString();
|
539
|
+
const sheet = workbook.getWorksheets()[action.sheet_position];
|
540
|
+
let image = getShapeByType(
|
541
|
+
workbook,
|
542
|
+
action.sheet_position,
|
543
|
+
Number(action.args[1]),
|
544
|
+
ExcelScript.ShapeType.image
|
545
|
+
);
|
546
|
+
let imgName = image.getName();
|
547
|
+
let imgLeft = image.getLeft();
|
548
|
+
let imgTop = image.getTop();
|
549
|
+
let imgHeight = image.getHeight();
|
550
|
+
let imgWidth = image.getWidth();
|
551
|
+
image.delete();
|
552
|
+
|
553
|
+
const newImage = sheet.addImage(imageBase64);
|
554
|
+
newImage.setName(imgName);
|
555
|
+
newImage.setLeft(imgLeft);
|
556
|
+
newImage.setTop(imgTop);
|
557
|
+
newImage.setHeight(imgHeight);
|
558
|
+
newImage.setWidth(imgWidth);
|
559
|
+
}
|
560
|
+
registerCallback(updatePicture);
|
561
|
+
|
562
|
+
function alert(workbook: ExcelScript.Workbook, action: Action) {
|
563
|
+
// OfficeScripts doesn't have an any alert outside of DataValidation...
|
564
|
+
let myPrompt = action.args[0];
|
565
|
+
let myTitle = action.args[1]; // ignored
|
566
|
+
let myButtons = action.args[2]; // ignored
|
567
|
+
let myMode = action.args[3]; // ignored
|
568
|
+
let myCallback = action.args[4]; // ignored
|
569
|
+
throw myPrompt;
|
570
|
+
}
|
571
|
+
registerCallback(alert);
|
572
|
+
|
573
|
+
function setRangeName(workbook: ExcelScript.Workbook, action: Action) {
|
574
|
+
workbook.addNamedItem(action.args[0].toString(), getRange(workbook, action));
|
575
|
+
}
|
576
|
+
registerCallback(setRangeName);
|
577
|
+
|
578
|
+
function namesAdd(workbook: ExcelScript.Workbook, action: Action) {
|
579
|
+
let name = action.args[0].toString();
|
580
|
+
let refersTo = action.args[1].toString();
|
581
|
+
if (action.sheet_position === null) {
|
582
|
+
workbook.addNamedItem(name, refersTo);
|
583
|
+
} else {
|
584
|
+
workbook
|
585
|
+
.getWorksheets()
|
586
|
+
[action.sheet_position].addNamedItem(name, refersTo);
|
587
|
+
}
|
588
|
+
}
|
589
|
+
registerCallback(namesAdd);
|
590
|
+
|
591
|
+
function nameDelete(workbook: ExcelScript.Workbook, action: Action) {
|
592
|
+
let name = action.args[2].toString();
|
593
|
+
let book_scope = Boolean(action.args[4]);
|
594
|
+
let scope_sheet_index = Number(action.args[5]);
|
595
|
+
if (book_scope === true) {
|
596
|
+
workbook.getNamedItem(name).delete();
|
597
|
+
} else {
|
598
|
+
workbook.getWorksheets()[scope_sheet_index].getNamedItem(name).delete();
|
599
|
+
}
|
600
|
+
}
|
601
|
+
registerCallback(nameDelete);
|
602
|
+
|
603
|
+
function runMacro(workbook: ExcelScript.Workbook, action: Action) {
|
604
|
+
globalThis.callbacks[action.args[0].toString()](
|
605
|
+
workbook,
|
606
|
+
...action.args.slice(1)
|
607
|
+
);
|
608
|
+
}
|
609
|
+
registerCallback(runMacro);
|
610
|
+
|
611
|
+
function rangeDelete(workbook: ExcelScript.Workbook, action: Action) {
|
612
|
+
let shift = action.args[0].toString();
|
613
|
+
if (shift === "up") {
|
614
|
+
getRange(workbook, action).delete(ExcelScript.DeleteShiftDirection.up);
|
615
|
+
} else if (shift === "left") {
|
616
|
+
getRange(workbook, action).delete(ExcelScript.DeleteShiftDirection.left);
|
617
|
+
}
|
618
|
+
}
|
619
|
+
registerCallback(rangeDelete);
|
620
|
+
|
621
|
+
function rangeInsert(workbook: ExcelScript.Workbook, action: Action) {
|
622
|
+
let shift = action.args[0].toString();
|
623
|
+
if (shift === "down") {
|
624
|
+
getRange(workbook, action).insert(ExcelScript.InsertShiftDirection.down);
|
625
|
+
} else if (shift === "right") {
|
626
|
+
getRange(workbook, action).insert(ExcelScript.InsertShiftDirection.right);
|
627
|
+
}
|
628
|
+
}
|
629
|
+
registerCallback(rangeInsert);
|
630
|
+
|
631
|
+
function rangeSelect(workbook: ExcelScript.Workbook, action: Action) {
|
632
|
+
getRange(workbook, action).select();
|
633
|
+
}
|
634
|
+
registerCallback(rangeSelect);
|
635
|
+
|
636
|
+
function addTable(workbook: ExcelScript.Workbook, action: Action) {
|
637
|
+
let mytable = workbook
|
638
|
+
.getWorksheets()
|
639
|
+
[action.sheet_position].addTable(
|
640
|
+
action.args[0].toString(),
|
641
|
+
Boolean(action.args[1])
|
642
|
+
);
|
643
|
+
if (action.args[2] !== null) {
|
644
|
+
mytable.setPredefinedTableStyle(action.args[2].toString());
|
645
|
+
}
|
646
|
+
if (action.args[3] !== null) {
|
647
|
+
mytable.setName(action.args[3].toString());
|
648
|
+
}
|
649
|
+
}
|
650
|
+
registerCallback(addTable);
|
651
|
+
|
652
|
+
function setTableName(workbook: ExcelScript.Workbook, action: Action) {
|
653
|
+
const mytable = workbook.getWorksheets()[action.sheet_position].getTables()[
|
654
|
+
parseInt(action.args[0].toString())
|
655
|
+
];
|
656
|
+
mytable.setName(action.args[1].toString());
|
657
|
+
}
|
658
|
+
registerCallback(setTableName);
|
659
|
+
|
660
|
+
function resizeTable(workbook: ExcelScript.Workbook, action: Action) {
|
661
|
+
const mytable = workbook.getWorksheets()[action.sheet_position].getTables()[
|
662
|
+
parseInt(action.args[0].toString())
|
663
|
+
];
|
664
|
+
mytable.resize(action.args[1].toString());
|
665
|
+
}
|
666
|
+
registerCallback(resizeTable);
|
667
|
+
|
668
|
+
function showAutofilterTable(workbook: ExcelScript.Workbook, action: Action) {
|
669
|
+
const mytable = workbook.getWorksheets()[action.sheet_position].getTables()[
|
670
|
+
parseInt(action.args[0].toString())
|
671
|
+
];
|
672
|
+
mytable.setShowFilterButton(Boolean(action.args[1]));
|
673
|
+
}
|
674
|
+
registerCallback(showAutofilterTable);
|
675
|
+
|
676
|
+
function showHeadersTable(workbook: ExcelScript.Workbook, action: Action) {
|
677
|
+
const mytable = workbook.getWorksheets()[action.sheet_position].getTables()[
|
678
|
+
parseInt(action.args[0].toString())
|
679
|
+
];
|
680
|
+
mytable.setShowHeaders(Boolean(action.args[1]));
|
681
|
+
}
|
682
|
+
registerCallback(showHeadersTable);
|
683
|
+
|
684
|
+
function showTotalsTable(workbook: ExcelScript.Workbook, action: Action) {
|
685
|
+
const mytable = workbook.getWorksheets()[action.sheet_position].getTables()[
|
686
|
+
parseInt(action.args[0].toString())
|
687
|
+
];
|
688
|
+
mytable.setShowTotals(Boolean(action.args[1]));
|
689
|
+
}
|
690
|
+
registerCallback(showTotalsTable);
|
691
|
+
|
692
|
+
function setTableStyle(workbook: ExcelScript.Workbook, action: Action) {
|
693
|
+
const mytable = workbook.getWorksheets()[action.sheet_position].getTables()[
|
694
|
+
parseInt(action.args[0].toString())
|
695
|
+
];
|
696
|
+
mytable.setPredefinedTableStyle(action.args[1].toString());
|
697
|
+
}
|
698
|
+
registerCallback(setTableStyle);
|
699
|
+
|
700
|
+
function copyRange(workbook: ExcelScript.Workbook, action: Action) {
|
701
|
+
const destination = workbook
|
702
|
+
.getWorksheets()
|
703
|
+
[parseInt(action.args[0].toString())].getRange(action.args[1].toString());
|
704
|
+
destination.copyFrom(getRange(workbook, action));
|
705
|
+
}
|
706
|
+
registerCallback(copyRange);
|
707
|
+
|
708
|
+
function sheetDelete(workbook: ExcelScript.Workbook, action: Action) {
|
709
|
+
workbook.getWorksheets()[action.sheet_position].delete();
|
710
|
+
}
|
711
|
+
registerCallback(sheetDelete);
|
712
|
+
|
713
|
+
function sheetClear(workbook: ExcelScript.Workbook, action: Action) {
|
714
|
+
const sheet = workbook.getWorksheets()[action.sheet_position];
|
715
|
+
sheet.getRanges().clear();
|
716
|
+
}
|
717
|
+
registerCallback(sheetClear);
|
718
|
+
|
719
|
+
function sheetClearFormats(workbook: ExcelScript.Workbook, action: Action) {
|
720
|
+
const sheet = workbook.getWorksheets()[action.sheet_position];
|
721
|
+
sheet.getRanges().clear(ExcelScript.ClearApplyTo.formats);
|
722
|
+
}
|
723
|
+
registerCallback(sheetClearFormats);
|
724
|
+
|
725
|
+
function sheetClearContents(workbook: ExcelScript.Workbook, action: Action) {
|
726
|
+
const sheet = workbook.getWorksheets()[action.sheet_position];
|
727
|
+
sheet.getRanges().clear(ExcelScript.ClearApplyTo.contents);
|
728
|
+
}
|
729
|
+
registerCallback(sheetClearContents);
|