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,577 @@
|
|
1
|
+
function hello() {
|
2
|
+
runPython("url", { auth: "DEVELOPMENT" });
|
3
|
+
}
|
4
|
+
|
5
|
+
/**
|
6
|
+
* xlwings for Google Apps Script
|
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
|
+
/**
|
37
|
+
* @OnlyCurrentDoc
|
38
|
+
*/
|
39
|
+
|
40
|
+
function runPython(
|
41
|
+
url,
|
42
|
+
{ auth = "", apiKey = "", include = "", exclude = "", headers = {} } = {}
|
43
|
+
) {
|
44
|
+
const version = "0.31.6";
|
45
|
+
const workbook = SpreadsheetApp.getActive();
|
46
|
+
const sheets = workbook.getSheets();
|
47
|
+
|
48
|
+
// Only used to request permission for proper OAuth Scope
|
49
|
+
Session.getActiveUser().getEmail();
|
50
|
+
|
51
|
+
// Config
|
52
|
+
let configSheet = workbook.getSheetByName("xlwings.conf");
|
53
|
+
let config = {};
|
54
|
+
let configValues = {};
|
55
|
+
if (configSheet) {
|
56
|
+
configValues = workbook
|
57
|
+
.getSheetByName("xlwings.conf")
|
58
|
+
.getRange("A1")
|
59
|
+
.getDataRegion()
|
60
|
+
.getValues();
|
61
|
+
configValues.forEach((el) => (config[el[0].toString()] = el[1].toString()));
|
62
|
+
}
|
63
|
+
|
64
|
+
if (apiKey === "") {
|
65
|
+
apiKey = config["API_KEY"] || "";
|
66
|
+
}
|
67
|
+
|
68
|
+
if (auth === "") {
|
69
|
+
auth = config["AUTH"] || "";
|
70
|
+
}
|
71
|
+
|
72
|
+
if (include === "") {
|
73
|
+
include = config["INCLUDE"] || "";
|
74
|
+
}
|
75
|
+
let includeArray = [];
|
76
|
+
if (include !== "") {
|
77
|
+
includeArray = include.split(",").map((item) => item.trim());
|
78
|
+
}
|
79
|
+
|
80
|
+
if (exclude === "") {
|
81
|
+
exclude = config["EXCLUDE"] || "";
|
82
|
+
}
|
83
|
+
let excludeArray = [];
|
84
|
+
if (exclude !== "") {
|
85
|
+
excludeArray = exclude.split(",").map((item) => item.trim());
|
86
|
+
}
|
87
|
+
if (includeArray.length > 0 && excludeArray.length > 0) {
|
88
|
+
throw "Either use 'include' or 'exclude', but not both!";
|
89
|
+
}
|
90
|
+
if (includeArray.length > 0) {
|
91
|
+
sheets.forEach((sheet) => {
|
92
|
+
if (!includeArray.includes(sheet.getName())) {
|
93
|
+
excludeArray.push(sheet.getName());
|
94
|
+
}
|
95
|
+
});
|
96
|
+
}
|
97
|
+
|
98
|
+
if (Object.keys(headers).length === 0) {
|
99
|
+
for (const property in config) {
|
100
|
+
if (property.toLowerCase().startsWith("header_")) {
|
101
|
+
headers[property.substring(7)] = config[property];
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
// Deprecated: replaced by "auth"
|
106
|
+
if (!("Authorization" in headers) && apiKey.length > 0) {
|
107
|
+
headers["Authorization"] = apiKey;
|
108
|
+
}
|
109
|
+
if (!("Authorization" in headers) && auth.length > 0) {
|
110
|
+
headers["Authorization"] = auth;
|
111
|
+
}
|
112
|
+
|
113
|
+
// Request payload
|
114
|
+
let payload = {};
|
115
|
+
payload["client"] = "Google Apps Script";
|
116
|
+
payload["version"] = version;
|
117
|
+
payload["book"] = {
|
118
|
+
name: workbook.getName(),
|
119
|
+
active_sheet_index: workbook.getActiveSheet().getIndex() - 1,
|
120
|
+
selection: workbook.getActiveRange().getA1Notation(),
|
121
|
+
};
|
122
|
+
|
123
|
+
// Names
|
124
|
+
let names = [];
|
125
|
+
workbook.getNamedRanges().forEach((namedRange, ix) => {
|
126
|
+
let name = namedRange.getName().includes(" ")
|
127
|
+
? namedRange.getName()
|
128
|
+
: namedRange.getName().replace("'", "").replace("'", "");
|
129
|
+
names[ix] = {
|
130
|
+
name: name,
|
131
|
+
sheet_index: namedRange.getRange().getSheet().getIndex() - 1,
|
132
|
+
address: namedRange.getRange().getA1Notation(),
|
133
|
+
// Sheet scope can only be created by copying a sheet (?)
|
134
|
+
scope_sheet_name: namedRange.getName().includes("!")
|
135
|
+
? namedRange.getRange().getSheet().getName()
|
136
|
+
: null,
|
137
|
+
scope_sheet_index: namedRange.getName().includes("!")
|
138
|
+
? namedRange.getRange().getSheet().getIndex() - 1
|
139
|
+
: null,
|
140
|
+
book_scope: !namedRange.getName().includes("!"),
|
141
|
+
};
|
142
|
+
});
|
143
|
+
payload["names"] = names;
|
144
|
+
|
145
|
+
payload["sheets"] = [];
|
146
|
+
let lastCellCol;
|
147
|
+
let lastCellRow;
|
148
|
+
let values;
|
149
|
+
sheets.forEach((sheet) => {
|
150
|
+
lastCellCol = sheet.getLastColumn();
|
151
|
+
lastCellRow = sheet.getLastRow();
|
152
|
+
if (excludeArray.includes(sheet.getName())) {
|
153
|
+
values = [[]];
|
154
|
+
} else {
|
155
|
+
let range = sheet.getRange(
|
156
|
+
1,
|
157
|
+
1,
|
158
|
+
lastCellRow > 0 ? lastCellRow : 1,
|
159
|
+
lastCellCol > 0 ? lastCellCol : 1
|
160
|
+
);
|
161
|
+
values = range.getValues();
|
162
|
+
// Handle dates
|
163
|
+
values.forEach((valueRow, rowIndex) => {
|
164
|
+
valueRow.forEach((value, colIndex) => {
|
165
|
+
if (value instanceof Date) {
|
166
|
+
// Convert from script timezone to spreadsheet timezone
|
167
|
+
let tzDate = new Date(
|
168
|
+
value
|
169
|
+
.toLocaleString("en-US", {
|
170
|
+
timeZone: workbook.getSpreadsheetTimeZone(),
|
171
|
+
})
|
172
|
+
.replace(/\u202F/, " ") // https://bugs.chromium.org/p/v8/issues/detail?id=13494
|
173
|
+
);
|
174
|
+
// toISOString transforms to UTC, so we need to correct for offset
|
175
|
+
values[rowIndex][colIndex] = new Date(
|
176
|
+
tzDate.getTime() - tzDate.getTimezoneOffset() * 60 * 1000
|
177
|
+
).toISOString();
|
178
|
+
}
|
179
|
+
});
|
180
|
+
});
|
181
|
+
}
|
182
|
+
|
183
|
+
let pictures = [];
|
184
|
+
if (excludeArray.includes(sheet.getName())) {
|
185
|
+
pictures = [];
|
186
|
+
} else {
|
187
|
+
sheet.getImages().forEach((image, ix) => {
|
188
|
+
pictures[ix] = {
|
189
|
+
name: image.getAltTextTitle(),
|
190
|
+
height: image.getHeight(),
|
191
|
+
width: image.getWidth(),
|
192
|
+
};
|
193
|
+
});
|
194
|
+
}
|
195
|
+
|
196
|
+
payload["sheets"].push({
|
197
|
+
name: sheet.getName(),
|
198
|
+
values: values,
|
199
|
+
pictures: pictures,
|
200
|
+
tables: [],
|
201
|
+
});
|
202
|
+
});
|
203
|
+
|
204
|
+
// console.log(payload);
|
205
|
+
|
206
|
+
// API call
|
207
|
+
const options = {
|
208
|
+
method: "post",
|
209
|
+
contentType: "application/json",
|
210
|
+
payload: JSON.stringify(payload),
|
211
|
+
headers: headers,
|
212
|
+
muteHttpExceptions: true,
|
213
|
+
};
|
214
|
+
|
215
|
+
// Parse JSON response
|
216
|
+
const response = UrlFetchApp.fetch(url, options);
|
217
|
+
if (response.getResponseCode() !== 200) {
|
218
|
+
throw response.getContentText();
|
219
|
+
}
|
220
|
+
const json = response.getContentText();
|
221
|
+
const rawData = JSON.parse(json);
|
222
|
+
|
223
|
+
// console.log(rawData);
|
224
|
+
|
225
|
+
// Run Functions
|
226
|
+
if (rawData !== null) {
|
227
|
+
const forceSync = ["sheet"];
|
228
|
+
rawData["actions"].forEach((action) => {
|
229
|
+
if (forceSync.some((el) => action.func.toLowerCase().includes(el))) {
|
230
|
+
SpreadsheetApp.flush(); // Force sync to prevent writing to wrong sheet
|
231
|
+
}
|
232
|
+
funcs[action.func](workbook, action);
|
233
|
+
});
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
// Helpers
|
238
|
+
function getRange(workbook, action) {
|
239
|
+
return workbook
|
240
|
+
.getSheets()
|
241
|
+
[action.sheet_position].getRange(
|
242
|
+
action.start_row + 1,
|
243
|
+
action.start_column + 1,
|
244
|
+
action.row_count,
|
245
|
+
action.column_count
|
246
|
+
);
|
247
|
+
}
|
248
|
+
|
249
|
+
// Functions map
|
250
|
+
let funcs = this;
|
251
|
+
|
252
|
+
// Functions
|
253
|
+
function setValues(workbook, action) {
|
254
|
+
// Handle DateTime (TODO: backend should deliver indices with datetime obj)
|
255
|
+
let dt;
|
256
|
+
let dtString;
|
257
|
+
let locale = workbook.getSpreadsheetLocale().replace("_", "-");
|
258
|
+
action.values.forEach((valueRow, rowIndex) => {
|
259
|
+
valueRow.forEach((value, colIndex) => {
|
260
|
+
if (
|
261
|
+
typeof value === "string" &&
|
262
|
+
value.length > 18 &&
|
263
|
+
value.includes("T")
|
264
|
+
) {
|
265
|
+
dt = new Date(Date.parse(value));
|
266
|
+
dtString = dt.toLocaleDateString(locale);
|
267
|
+
if (dtString !== "Invalid Date") {
|
268
|
+
let hours = dt.getHours();
|
269
|
+
let minutes = dt.getMinutes();
|
270
|
+
let seconds = dt.getSeconds();
|
271
|
+
let milliseconds = dt.getMilliseconds();
|
272
|
+
if (hours + minutes + seconds + milliseconds !== 0) {
|
273
|
+
// The time doesn't follow the locale in the Date Time combination!
|
274
|
+
dtString +=
|
275
|
+
" " + hours + ":" + minutes + ":" + seconds + "." + milliseconds;
|
276
|
+
}
|
277
|
+
action.values[rowIndex][colIndex] = dtString;
|
278
|
+
}
|
279
|
+
}
|
280
|
+
});
|
281
|
+
});
|
282
|
+
getRange(workbook, action).setValues(action.values);
|
283
|
+
}
|
284
|
+
|
285
|
+
function rangeClearContents(workbook, action) {
|
286
|
+
getRange(workbook, action).clearContent();
|
287
|
+
}
|
288
|
+
|
289
|
+
function rangeClearFormats(workbook, action) {
|
290
|
+
getRange(workbook, action).clearFormat();
|
291
|
+
}
|
292
|
+
|
293
|
+
function rangeClear(workbook, action) {
|
294
|
+
getRange(workbook, action).clear();
|
295
|
+
}
|
296
|
+
|
297
|
+
function addSheet(workbook, action) {
|
298
|
+
// insertSheet(sheetName, sheetIndex)
|
299
|
+
let sheet = workbook.insertSheet(action.args[1], parseInt(action.args[0]));
|
300
|
+
}
|
301
|
+
|
302
|
+
function setSheetName(workbook, action) {
|
303
|
+
workbook
|
304
|
+
.getSheets()
|
305
|
+
[action.sheet_position].setName(action.args[0].toString());
|
306
|
+
}
|
307
|
+
|
308
|
+
function setAutofit(workbook, action) {
|
309
|
+
if (action.args[0] === "columns") {
|
310
|
+
workbook
|
311
|
+
.getSheets()
|
312
|
+
[action.sheet_position].autoResizeColumns(
|
313
|
+
action.start_column + 1,
|
314
|
+
action.column_count
|
315
|
+
);
|
316
|
+
} else {
|
317
|
+
workbook
|
318
|
+
.getSheets()
|
319
|
+
[action.sheet_position].autoResizeRows(
|
320
|
+
action.start_row + 1,
|
321
|
+
action.row_count
|
322
|
+
);
|
323
|
+
}
|
324
|
+
}
|
325
|
+
|
326
|
+
function setRangeColor(workbook, action) {
|
327
|
+
getRange(workbook, action).setBackground(action.args[0]);
|
328
|
+
}
|
329
|
+
|
330
|
+
function activateSheet(workbook, action) {
|
331
|
+
workbook.getSheets()[parseInt(action.args[0])].activate();
|
332
|
+
}
|
333
|
+
|
334
|
+
function addHyperlink(workbook, action) {
|
335
|
+
let value = SpreadsheetApp.newRichTextValue()
|
336
|
+
.setText(action.args[1])
|
337
|
+
.setLinkUrl(action.args[0])
|
338
|
+
.build();
|
339
|
+
getRange(workbook, action).setRichTextValue(value);
|
340
|
+
}
|
341
|
+
|
342
|
+
function setNumberFormat(workbook, action) {
|
343
|
+
getRange(workbook, action).setNumberFormat(action.args[0]);
|
344
|
+
}
|
345
|
+
|
346
|
+
function setPictureName(workbook, action) {
|
347
|
+
workbook
|
348
|
+
.getSheets()
|
349
|
+
[action.sheet_position].getImages()
|
350
|
+
[action.args[0]].setAltTextTitle(action.args[1]);
|
351
|
+
}
|
352
|
+
|
353
|
+
function setPictureHeight(workbook, action) {
|
354
|
+
workbook
|
355
|
+
.getSheets()
|
356
|
+
[action.sheet_position].getImages()
|
357
|
+
[action.args[0]].setHeight(action.args[1]);
|
358
|
+
}
|
359
|
+
|
360
|
+
function setPictureWidth(workbook, action) {
|
361
|
+
workbook
|
362
|
+
.getSheets()
|
363
|
+
[action.sheet_position].getImages()
|
364
|
+
[action.args[0]].setWidth(action.args[1]);
|
365
|
+
}
|
366
|
+
|
367
|
+
function deletePicture(workbook, action) {
|
368
|
+
workbook
|
369
|
+
.getSheets()
|
370
|
+
[action.sheet_position].getImages()
|
371
|
+
[action.args[0]].remove();
|
372
|
+
}
|
373
|
+
|
374
|
+
function addPicture(workbook, action) {
|
375
|
+
let imageBlob = Utilities.newBlob(
|
376
|
+
Utilities.base64Decode(action.args[0]),
|
377
|
+
"image/png",
|
378
|
+
"MyImageName"
|
379
|
+
);
|
380
|
+
workbook
|
381
|
+
.getSheets()
|
382
|
+
[action.sheet_position].insertImage(
|
383
|
+
imageBlob,
|
384
|
+
action.args[1] + 1,
|
385
|
+
action.args[2] + 1
|
386
|
+
);
|
387
|
+
SpreadsheetApp.flush();
|
388
|
+
}
|
389
|
+
|
390
|
+
function updatePicture(workbook, action) {
|
391
|
+
// Workaround as img.replace() doesn't manage to refresh the screen half of the time
|
392
|
+
let imageBlob = Utilities.newBlob(
|
393
|
+
Utilities.base64Decode(action.args[0]),
|
394
|
+
"image/png",
|
395
|
+
"MyImageName"
|
396
|
+
);
|
397
|
+
let img = workbook.getSheets()[action.sheet_position].getImages()[
|
398
|
+
action.args[1]
|
399
|
+
];
|
400
|
+
let altTextTitle = img.getAltTextTitle();
|
401
|
+
let rowIndex = img.getAnchorCell().getRowIndex();
|
402
|
+
let colIndex = img.getAnchorCell().getColumnIndex();
|
403
|
+
let xOffset = img.getAnchorCellXOffset();
|
404
|
+
let yOffset = img.getAnchorCellYOffset();
|
405
|
+
let width = img.getWidth();
|
406
|
+
let height = img.getHeight();
|
407
|
+
// Seems to help if the new image is inserted first before deleting the old one
|
408
|
+
imgNew = workbook
|
409
|
+
.getSheets()
|
410
|
+
[action.sheet_position].insertImage(
|
411
|
+
imageBlob,
|
412
|
+
colIndex,
|
413
|
+
rowIndex,
|
414
|
+
xOffset,
|
415
|
+
yOffset
|
416
|
+
);
|
417
|
+
img.remove();
|
418
|
+
imgNew.setAltTextTitle(altTextTitle);
|
419
|
+
imgNew.setWidth(width);
|
420
|
+
imgNew.setHeight(height);
|
421
|
+
SpreadsheetApp.flush();
|
422
|
+
}
|
423
|
+
|
424
|
+
function alert(workbook, action) {
|
425
|
+
let ui = SpreadsheetApp.getUi();
|
426
|
+
|
427
|
+
let myPrompt = action.args[0];
|
428
|
+
let myTitle = action.args[1];
|
429
|
+
let myButtons = action.args[2];
|
430
|
+
let myMode = action.args[3]; // ignored
|
431
|
+
let myCallback = action.args[4];
|
432
|
+
|
433
|
+
if (myButtons == "ok") {
|
434
|
+
myButtons = ui.ButtonSet.OK;
|
435
|
+
} else if (myButtons == "ok_cancel") {
|
436
|
+
myButtons = ui.ButtonSet.OK_CANCEL;
|
437
|
+
} else if (myButtons == "yes_no") {
|
438
|
+
myButtons = ui.ButtonSet.YES_NO;
|
439
|
+
} else if (myButtons == "yes_no_cancel") {
|
440
|
+
myButtons = ui.ButtonSet.YES_NO_CANCEL;
|
441
|
+
}
|
442
|
+
|
443
|
+
let rv = ui.alert(myTitle, myPrompt, myButtons);
|
444
|
+
|
445
|
+
let buttonResult;
|
446
|
+
if (rv == ui.Button.OK) {
|
447
|
+
buttonResult = "ok";
|
448
|
+
} else if (rv == ui.Button.CANCEL) {
|
449
|
+
buttonResult = "cancel";
|
450
|
+
} else if (rv == ui.Button.YES) {
|
451
|
+
buttonResult = "yes";
|
452
|
+
} else if (rv == ui.Button.NO) {
|
453
|
+
buttonResult = "no";
|
454
|
+
}
|
455
|
+
|
456
|
+
if (myCallback != "") {
|
457
|
+
funcs[myCallback](buttonResult);
|
458
|
+
}
|
459
|
+
}
|
460
|
+
|
461
|
+
function setRangeName(workbook, action) {
|
462
|
+
let range = getRange(workbook, action);
|
463
|
+
range.getSheet().getParent().setNamedRange(action.args[0], range);
|
464
|
+
}
|
465
|
+
|
466
|
+
function namesAdd(workbook, action) {
|
467
|
+
let name = action.args[0];
|
468
|
+
if (name.includes("!")) {
|
469
|
+
throw "NotImplemented: sheet scoped names";
|
470
|
+
}
|
471
|
+
let refersTo = action.args[1];
|
472
|
+
const parts = refersTo.split("!");
|
473
|
+
const address = parts[1];
|
474
|
+
let sheetName = parts[0];
|
475
|
+
if (sheetName.charAt(0) === "=") {
|
476
|
+
sheetName = sheetName.substring(1);
|
477
|
+
}
|
478
|
+
if (sheetName.includes(" ")) {
|
479
|
+
sheetName = sheetName.replace("'", "").replace("'", "");
|
480
|
+
}
|
481
|
+
let range = workbook.getSheetByName(sheetName).getRange(address);
|
482
|
+
range.getSheet().getParent().setNamedRange(name, range);
|
483
|
+
}
|
484
|
+
|
485
|
+
function nameDelete(workbook, action) {
|
486
|
+
// workbook.removeNamedRange(name) doesn't work with sheet scoped names
|
487
|
+
function processName(name) {
|
488
|
+
if (name.includes("!")) {
|
489
|
+
const [sheetName, definedName] = name.split("!");
|
490
|
+
if (!sheetName.startsWith("'")) {
|
491
|
+
return `'${sheetName}'!${definedName}`;
|
492
|
+
}
|
493
|
+
}
|
494
|
+
return name;
|
495
|
+
}
|
496
|
+
workbook.getNamedRanges().forEach((namedRange) => {
|
497
|
+
if (namedRange.getName() === processName(action.args[0])) {
|
498
|
+
namedRange.remove();
|
499
|
+
return;
|
500
|
+
}
|
501
|
+
});
|
502
|
+
}
|
503
|
+
|
504
|
+
function runMacro(workbook, action) {
|
505
|
+
funcs[action.args[0]](workbook, ...action.args.slice(1));
|
506
|
+
}
|
507
|
+
|
508
|
+
function rangeDelete(workbook, action) {
|
509
|
+
if (action.args[0] === "up") {
|
510
|
+
getRange(workbook, action).deleteCells(SpreadsheetApp.Dimension.ROWS);
|
511
|
+
} else {
|
512
|
+
getRange(workbook, action).deleteCells(SpreadsheetApp.Dimension.COLUMNS);
|
513
|
+
}
|
514
|
+
}
|
515
|
+
|
516
|
+
function rangeInsert(workbook, action) {
|
517
|
+
if (action.args[0] === "down") {
|
518
|
+
getRange(workbook, action).insertCells(SpreadsheetApp.Dimension.ROWS);
|
519
|
+
} else {
|
520
|
+
getRange(workbook, action).insertCells(SpreadsheetApp.Dimension.COLUMNS);
|
521
|
+
}
|
522
|
+
}
|
523
|
+
|
524
|
+
function rangeSelect(workbook, action) {
|
525
|
+
getRange(workbook, action).activate();
|
526
|
+
}
|
527
|
+
|
528
|
+
function addTable(workbook, action) {
|
529
|
+
throw "NotImplemented: addTable";
|
530
|
+
}
|
531
|
+
|
532
|
+
function setTableName(workbook, action) {
|
533
|
+
throw "NotImplemented: setTableName";
|
534
|
+
}
|
535
|
+
|
536
|
+
function resizeTable(workbook, action) {
|
537
|
+
throw "NotImplemented: resizeTable";
|
538
|
+
}
|
539
|
+
|
540
|
+
function showAutofilterTable(workbook, action) {
|
541
|
+
throw "NotImplemented: showAutofilterTable";
|
542
|
+
}
|
543
|
+
|
544
|
+
function showHeadersTable(workbook, action) {
|
545
|
+
throw "NotImplemented: showHeadersTable";
|
546
|
+
}
|
547
|
+
|
548
|
+
function showTotalsTable(workbook, action) {
|
549
|
+
throw "NotImplemented: showTotalsTable";
|
550
|
+
}
|
551
|
+
|
552
|
+
function setTableStyle(workbook, action) {
|
553
|
+
throw "NotImplemented: setTableStyle";
|
554
|
+
}
|
555
|
+
|
556
|
+
function copyRange(workbook, action) {
|
557
|
+
const destination = workbook
|
558
|
+
.getSheets()
|
559
|
+
[parseInt(action.args[0])].getRange(action.args[1].toString());
|
560
|
+
getRange(workbook, action).copyTo(destination);
|
561
|
+
}
|
562
|
+
|
563
|
+
function sheetDelete(workbook, action) {
|
564
|
+
workbook.deleteSheet(workbook.getSheets()[action.sheet_position]);
|
565
|
+
}
|
566
|
+
|
567
|
+
function sheetClear(workbook, action) {
|
568
|
+
workbook.getSheets()[action.sheet_position].clear();
|
569
|
+
}
|
570
|
+
|
571
|
+
function sheetClearFormats(workbook, action) {
|
572
|
+
workbook.getSheets()[action.sheet_position].clearFormats();
|
573
|
+
}
|
574
|
+
|
575
|
+
function sheetClearContents(workbook, action) {
|
576
|
+
workbook.getSheets()[action.sheet_position].clearContents();
|
577
|
+
}
|