javascript-excel 2.3.0 → 2.4.0
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.
- package/README.md +1 -1
- package/dist/{csv-f4P3fGs-.cjs → csv-DZ241Y5F.cjs} +24 -0
- package/dist/{csv-Bck8eW_D.js → csv-Dn4MIESx.js} +24 -0
- package/dist/csv.cjs +1 -1
- package/dist/csv.d.cts +8 -0
- package/dist/csv.d.ts +8 -0
- package/dist/csv.js +1 -1
- package/dist/{dataset-DzoMeOG1.cjs → dataset-CbZnEWXu.cjs} +45 -1
- package/dist/{dataset-BLo9CwB-.js → dataset-CyEHVht4.js} +46 -2
- package/dist/import.cjs +1 -1
- package/dist/import.d.cts +1 -1
- package/dist/import.d.ts +1 -1
- package/dist/import.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/{pipeline-D1eAhqJu.d.cts → pipeline-4U7Xnuc1.d.cts} +6 -3
- package/dist/{pipeline-Bh7FUyzW.d.ts → pipeline-BegSPu8X.d.ts} +6 -3
- package/dist/{pipeline-LCTU0Eg_.cjs → pipeline-BwkRpV5Z.cjs} +30 -8
- package/dist/{pipeline-2dgQM9E9.js → pipeline-C8F9lecW.js} +30 -8
- package/dist/{read-BYI7EVMo.cjs → read-DmUPztqh.cjs} +308 -89
- package/dist/{read-BnXzPjGc.js → read-cvxu6O-H.js} +297 -90
- package/dist/read.cjs +1 -1
- package/dist/read.d.cts +24 -1
- package/dist/read.d.ts +24 -1
- package/dist/read.js +1 -1
- package/dist/worker.cjs +3 -3
- package/dist/worker.d.cts +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +3 -3
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { r as readCsv } from "./csv-
|
|
2
|
-
import { i as toDatasetDetailed } from "./dataset-
|
|
1
|
+
import { r as readCsv } from "./csv-Dn4MIESx.js";
|
|
2
|
+
import { i as toDatasetDetailed } from "./dataset-CyEHVht4.js";
|
|
3
3
|
import { a as LimitError, i as FormatError, o as ValidationError } from "./errors-CvGlfw0E.js";
|
|
4
|
-
import { a as
|
|
4
|
+
import { a as readImpl, c as DEFAULT_LIMITS, i as readSheetNames, n as detectFormat, o as excerpt, s as quoted } from "./read-cvxu6O-H.js";
|
|
5
5
|
import { a as toBytes, i as checkMaxWarnings, n as parseIsoDate } from "./infer-DcUyZ1T-.js";
|
|
6
6
|
import { a as decodeRange } from "./address-DUn7-5OS.js";
|
|
7
7
|
import { t as isoDate } from "./iso-date-CXnn-9mT.js";
|
|
@@ -612,6 +612,20 @@ function startOfDay(d, zone) {
|
|
|
612
612
|
function isExcelDayZero(d, zone) {
|
|
613
613
|
return zone === "utc" ? d.getUTCFullYear() === 1899 && d.getUTCMonth() === 11 && d.getUTCDate() === 31 : d.getFullYear() === 1899 && d.getMonth() === 11 && d.getDate() === 31;
|
|
614
614
|
}
|
|
615
|
+
/**
|
|
616
|
+
* For 'day' (JSE-69): ISO text with an explicit offset or `Z` names its day in
|
|
617
|
+
* its date part, so that day, at 00:00 in `zone`; the offset does not move it.
|
|
618
|
+
* Undefined for anything else, including text the ISO parser refuses (an
|
|
619
|
+
* invalid date, time or offset), which then goes the usual way.
|
|
620
|
+
*/
|
|
621
|
+
function isoDayAsWritten(text, zone) {
|
|
622
|
+
const s = text.trim();
|
|
623
|
+
if (s.length <= 16 || s.charCodeAt(4) !== 45 || parseIsoDate(s, zone) === void 0) return void 0;
|
|
624
|
+
for (let i = 11; i < s.length; i++) {
|
|
625
|
+
const c = s.charCodeAt(i);
|
|
626
|
+
if (c === 90 || c === 43 || c === 45) return parseIsoDate(s.slice(0, 10), zone);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
615
629
|
function textOf(v) {
|
|
616
630
|
if (typeof v === "string") return v;
|
|
617
631
|
if (v && typeof v === "object" && "richText" in v) return v.richText.map((r) => r.text).join("");
|
|
@@ -825,8 +839,11 @@ function convert(v, col, locale, zone) {
|
|
|
825
839
|
let d;
|
|
826
840
|
if (v instanceof Date) d = v;
|
|
827
841
|
else if (t !== void 0) {
|
|
828
|
-
|
|
829
|
-
|
|
842
|
+
if (col.type === "day") d = isoDayAsWritten(t, zone);
|
|
843
|
+
if (d === void 0) {
|
|
844
|
+
const order = col.dateOrder ?? (locale.dateOrder && locale.dateOrder !== "auto" ? locale.dateOrder : void 0);
|
|
845
|
+
d = order ? textToDate(t, order, zone, locale.twoDigitYearPivot) : parseDate(t, { zone });
|
|
846
|
+
}
|
|
830
847
|
}
|
|
831
848
|
if (d === void 0) return { ok: false };
|
|
832
849
|
if (col.type !== "day") return {
|
|
@@ -1006,6 +1023,8 @@ async function importDataset(input, options = {}) {
|
|
|
1006
1023
|
if (o.maxIssues !== Number.POSITIVE_INFINITY) checkCount("maxIssues", o.maxIssues, 1);
|
|
1007
1024
|
const maxText = o.limits?.maxCellTextLength;
|
|
1008
1025
|
if (maxText !== void 0 && (typeof maxText !== "number" || !(maxText > 0))) throw new TypeError("limits.maxCellTextLength must be a positive number");
|
|
1026
|
+
const maxColumns = o.limits?.maxColumns;
|
|
1027
|
+
if (maxColumns !== void 0 && (typeof maxColumns !== "number" || !(maxColumns > 0))) throw new TypeError("limits.maxColumns must be a positive number");
|
|
1009
1028
|
if (typeof o.header === "object" && o.header !== null) {
|
|
1010
1029
|
checkCount("header.rows", o.header.rows, 1);
|
|
1011
1030
|
checkCount("header.row", o.header.row, 0);
|
|
@@ -1059,6 +1078,7 @@ async function importDataset(input, options = {}) {
|
|
|
1059
1078
|
maxRows: cap,
|
|
1060
1079
|
maxWarnings: o.limits?.maxWarnings,
|
|
1061
1080
|
maxCellTextLength: maxText,
|
|
1081
|
+
maxColumns,
|
|
1062
1082
|
maxFieldBytes: maxText !== void 0 && maxText > 1048576 ? 3 * maxText : void 0,
|
|
1063
1083
|
signal: o.signal,
|
|
1064
1084
|
inferTypes: false
|
|
@@ -1085,7 +1105,7 @@ async function importDataset(input, options = {}) {
|
|
|
1085
1105
|
sheet: want,
|
|
1086
1106
|
sheets: sheets.map((s) => s.name)
|
|
1087
1107
|
} });
|
|
1088
|
-
const { workbook } = await
|
|
1108
|
+
const { workbook } = await readImpl(bytes, {
|
|
1089
1109
|
sheets: [info.index],
|
|
1090
1110
|
styles: false,
|
|
1091
1111
|
richText: "plain",
|
|
@@ -1100,7 +1120,7 @@ async function importDataset(input, options = {}) {
|
|
|
1100
1120
|
if (w.code === "ROWS_TRUNCATED") truncatedRead = true;
|
|
1101
1121
|
warn(w);
|
|
1102
1122
|
}
|
|
1103
|
-
});
|
|
1123
|
+
}, { sharedFormulaText: "master" });
|
|
1104
1124
|
sheet = workbook.sheets[info.index];
|
|
1105
1125
|
meta.sheet = {
|
|
1106
1126
|
name: info.name,
|
|
@@ -1139,13 +1159,15 @@ async function importDataset(input, options = {}) {
|
|
|
1139
1159
|
headerRows = Array.from({ length: header.rows }, (_, i) => start + i);
|
|
1140
1160
|
join = header.join;
|
|
1141
1161
|
}
|
|
1162
|
+
const maxCells = o.limits?.maxCells;
|
|
1163
|
+
if (maxCells !== void 0 && (typeof maxCells !== "number" || !(maxCells > 0))) throw new TypeError("limits.maxCells must be a positive number");
|
|
1142
1164
|
const ds = toDatasetDetailed(sheet, {
|
|
1143
1165
|
headerRow: headerRows.length ? headerRows[0] : false,
|
|
1144
1166
|
headerRows: Math.max(1, headerRows.length),
|
|
1145
1167
|
join,
|
|
1146
1168
|
range: o.range,
|
|
1147
1169
|
skipTotals: o.skipTotals ?? "auto"
|
|
1148
|
-
});
|
|
1170
|
+
}, { maxCells: maxCells ?? DEFAULT_LIMITS.maxCells });
|
|
1149
1171
|
const issueCap = new IssueCap(o.maxIssues ?? 1e5);
|
|
1150
1172
|
const issues = issueCap.issues;
|
|
1151
1173
|
const base = {
|
|
@@ -18,6 +18,7 @@ const DEFAULT_LIMITS = Object.freeze({
|
|
|
18
18
|
maxItems: 1e7,
|
|
19
19
|
maxSharedStrings: 5e6,
|
|
20
20
|
maxCellTextLength: 1048576,
|
|
21
|
+
maxColumns: 16384,
|
|
21
22
|
maxWarnings: 1e3
|
|
22
23
|
});
|
|
23
24
|
function head(s) {
|
|
@@ -1197,13 +1198,17 @@ function resolveTarget(baseDir, target) {
|
|
|
1197
1198
|
* references, external workbook indexes) are copied unchanged. Returns
|
|
1198
1199
|
* undefined when a shifted reference would leave the sheet, so the caller
|
|
1199
1200
|
* keeps the cached value only.
|
|
1201
|
+
*
|
|
1202
|
+
* A master formula is scanned once (`compileFormula`) into the text between its
|
|
1203
|
+
* references and the references themselves; each cell that shares it then costs
|
|
1204
|
+
* its number of references plus the length of its own text (`shiftCompiled`),
|
|
1205
|
+
* and whether its references stay on the sheet is known in constant time
|
|
1206
|
+
* (`canShift`). Before JSE-62 every cell rescanned the master character by
|
|
1207
|
+
* character and built its text with `+=`, so N cells sharing a long formula
|
|
1208
|
+
* cost N times the master's length in time and much more in memory.
|
|
1200
1209
|
*/
|
|
1201
1210
|
const MAX_ROW = 1048576;
|
|
1202
1211
|
const MAX_COL = 16384;
|
|
1203
|
-
const CELL = /\$?([A-Za-z]{1,3})\$?(\d{1,7})/y;
|
|
1204
|
-
const CELL_PARTS = /^(\$?)([A-Za-z]{1,3})(\$?)(\d{1,7})$/;
|
|
1205
|
-
const COLS = /(\$?)([A-Za-z]{1,3}):(\$?)([A-Za-z]{1,3})/y;
|
|
1206
|
-
const ROWS = /(\$?)(\d{1,7}):(\$?)(\d{1,7})/y;
|
|
1207
1212
|
function colNumber(letters) {
|
|
1208
1213
|
let n = 0;
|
|
1209
1214
|
for (let i = 0; i < letters.length; i++) n = n * 26 + (letters.toUpperCase().charCodeAt(i) - 64);
|
|
@@ -1218,110 +1223,274 @@ function colLetters(n) {
|
|
|
1218
1223
|
}
|
|
1219
1224
|
return s;
|
|
1220
1225
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
1226
|
+
/** A letter or digit, by character code (JSE-62: a regex test per character made long masters slow). */
|
|
1227
|
+
function isAlnumCode(c) {
|
|
1228
|
+
return c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122;
|
|
1223
1229
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1230
|
+
/** Part of a word: a letter, digit, `_`, `.` or `\\`. */
|
|
1231
|
+
function isWordCode(c) {
|
|
1232
|
+
return isAlnumCode(c) || c === 95 || c === 46 || c === 92;
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Excel's own limit on the length of a formula. A shared formula's master that
|
|
1236
|
+
* is longer is not expanded into the cells that share it (JSE-62): no
|
|
1237
|
+
* spreadsheet application writes one, and expanding it multiplied a few KB of
|
|
1238
|
+
* file into gigabytes.
|
|
1239
|
+
*/
|
|
1240
|
+
const MAX_SHARED_FORMULA_LENGTH = 8192;
|
|
1241
|
+
/** Work done by the shifter, for the bounded-work tests (JSE-62). */
|
|
1242
|
+
const shiftWork = {
|
|
1243
|
+
compiles: 0,
|
|
1244
|
+
compiledChars: 0,
|
|
1245
|
+
shifts: 0,
|
|
1246
|
+
shiftedChars: 0
|
|
1247
|
+
};
|
|
1248
|
+
const COLS_REF = 0;
|
|
1249
|
+
const ROWS_REF = 1;
|
|
1250
|
+
const CELL_REF = 2;
|
|
1251
|
+
/**
|
|
1252
|
+
* Scans `formula` once, in time proportional to its length. With `boundsOnly`
|
|
1253
|
+
* only the relative bounds are kept (for `canShift`; no text can be built from
|
|
1254
|
+
* the result): what importDataset needs.
|
|
1255
|
+
*/
|
|
1256
|
+
function compileFormula(formula, boundsOnly = false) {
|
|
1257
|
+
shiftWork.compiles++;
|
|
1258
|
+
shiftWork.compiledChars += formula.length;
|
|
1259
|
+
const segs = [];
|
|
1260
|
+
const refs = [];
|
|
1261
|
+
let rowMin = 1e400;
|
|
1262
|
+
let rowMax = -1e400;
|
|
1263
|
+
let colMin = 1e400;
|
|
1264
|
+
let colMax = -1e400;
|
|
1265
|
+
const relRow = (anchor, v) => {
|
|
1266
|
+
if (anchor === "$") return;
|
|
1267
|
+
if (v < rowMin) rowMin = v;
|
|
1268
|
+
if (v > rowMax) rowMax = v;
|
|
1269
|
+
};
|
|
1270
|
+
const relCol = (anchor, v) => {
|
|
1271
|
+
if (anchor === "$") return;
|
|
1272
|
+
if (v < colMin) colMin = v;
|
|
1273
|
+
if (v > colMax) colMax = v;
|
|
1274
|
+
};
|
|
1275
|
+
let segStart = 0;
|
|
1227
1276
|
let i = 0;
|
|
1228
1277
|
const n = formula.length;
|
|
1229
1278
|
while (i < n) {
|
|
1230
|
-
const
|
|
1231
|
-
if (
|
|
1279
|
+
const code = formula.charCodeAt(i);
|
|
1280
|
+
if (code === 34 || code === 39) {
|
|
1232
1281
|
let j = i + 1;
|
|
1233
|
-
for (; j < n; j++) if (formula
|
|
1234
|
-
if (formula
|
|
1282
|
+
for (; j < n; j++) if (formula.charCodeAt(j) === code) {
|
|
1283
|
+
if (formula.charCodeAt(j + 1) === code) j++;
|
|
1235
1284
|
else break;
|
|
1236
1285
|
}
|
|
1237
|
-
out += formula.slice(i, j + 1);
|
|
1238
1286
|
i = j + 1;
|
|
1239
1287
|
continue;
|
|
1240
1288
|
}
|
|
1241
|
-
if (
|
|
1242
|
-
let j = i + 1;
|
|
1243
|
-
for (; j < n; j++) if (formula[j] === "'") {
|
|
1244
|
-
if (formula[j + 1] === "'") j++;
|
|
1245
|
-
else break;
|
|
1246
|
-
}
|
|
1247
|
-
out += formula.slice(i, j + 1);
|
|
1248
|
-
i = j + 1;
|
|
1249
|
-
continue;
|
|
1250
|
-
}
|
|
1251
|
-
if (ch === "[") {
|
|
1289
|
+
if (code === 91) {
|
|
1252
1290
|
let depth = 0;
|
|
1253
1291
|
let j = i;
|
|
1254
|
-
for (; j < n; j++)
|
|
1255
|
-
|
|
1256
|
-
|
|
1292
|
+
for (; j < n; j++) {
|
|
1293
|
+
const c = formula.charCodeAt(j);
|
|
1294
|
+
if (c === 91) depth++;
|
|
1295
|
+
else if (c === 93 && --depth === 0) break;
|
|
1296
|
+
}
|
|
1257
1297
|
i = j + 1;
|
|
1258
1298
|
continue;
|
|
1259
1299
|
}
|
|
1260
|
-
const prev = i > 0 ? formula
|
|
1261
|
-
if ((
|
|
1262
|
-
const
|
|
1263
|
-
if (
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1300
|
+
const prev = i > 0 ? formula.charCodeAt(i - 1) : -1;
|
|
1301
|
+
if ((code === 36 || isAlnumCode(code)) && !isWordCode(prev) && prev !== 36) {
|
|
1302
|
+
const ref = parseRef$1(formula, i);
|
|
1303
|
+
if (ref) {
|
|
1304
|
+
const r = ref.ref;
|
|
1305
|
+
if (!boundsOnly) {
|
|
1306
|
+
segs.push(formula.slice(segStart, i));
|
|
1307
|
+
refs.push(r);
|
|
1308
|
+
}
|
|
1309
|
+
if (r.kind === COLS_REF) {
|
|
1310
|
+
relCol(r.aAnchor, r.a);
|
|
1311
|
+
relCol(r.bAnchor, r.b);
|
|
1312
|
+
} else if (r.kind === ROWS_REF) {
|
|
1313
|
+
relRow(r.aAnchor, r.a);
|
|
1314
|
+
relRow(r.bAnchor, r.b);
|
|
1315
|
+
} else {
|
|
1316
|
+
relCol(r.aAnchor, r.a);
|
|
1317
|
+
relRow(r.bAnchor, r.b);
|
|
1318
|
+
}
|
|
1319
|
+
i = segStart = ref.end;
|
|
1267
1320
|
continue;
|
|
1268
1321
|
}
|
|
1269
1322
|
let j = i + 1;
|
|
1270
|
-
while (j < n &&
|
|
1271
|
-
out += formula.slice(i, j);
|
|
1323
|
+
while (j < n && isWordCode(formula.charCodeAt(j))) j++;
|
|
1272
1324
|
i = j;
|
|
1273
1325
|
continue;
|
|
1274
1326
|
}
|
|
1275
|
-
out += ch;
|
|
1276
1327
|
i++;
|
|
1277
1328
|
}
|
|
1278
|
-
return
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1329
|
+
if (boundsOnly) return {
|
|
1330
|
+
source: formula,
|
|
1331
|
+
segs: [],
|
|
1332
|
+
slots: [],
|
|
1333
|
+
uniq: [],
|
|
1334
|
+
literalLength: 0,
|
|
1335
|
+
rowMin,
|
|
1336
|
+
rowMax,
|
|
1337
|
+
colMin,
|
|
1338
|
+
colMax
|
|
1286
1339
|
};
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1340
|
+
segs.push(formula.slice(segStart));
|
|
1341
|
+
const outSegs = [segs[0]];
|
|
1342
|
+
const slots = [];
|
|
1343
|
+
const uniq = [];
|
|
1344
|
+
const index = /* @__PURE__ */ new Map();
|
|
1345
|
+
for (let k = 0; k < refs.length; k++) {
|
|
1346
|
+
const r = refs[k];
|
|
1347
|
+
const next = segs[k + 1];
|
|
1348
|
+
if (r.aAnchor === "$" && r.bAnchor === "$") {
|
|
1349
|
+
outSegs[outSegs.length - 1] += refText(r, 0, 0) + next;
|
|
1350
|
+
continue;
|
|
1351
|
+
}
|
|
1352
|
+
const key = `${r.kind}${r.aAnchor}${r.a},${r.bAnchor}${r.b}`;
|
|
1353
|
+
let u = index.get(key);
|
|
1354
|
+
if (u === void 0) {
|
|
1355
|
+
u = uniq.length;
|
|
1356
|
+
uniq.push(r);
|
|
1357
|
+
index.set(key, u);
|
|
1358
|
+
}
|
|
1359
|
+
slots.push(u);
|
|
1360
|
+
outSegs.push(next);
|
|
1298
1361
|
}
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1362
|
+
let literalLength = 0;
|
|
1363
|
+
for (const t of outSegs) literalLength += t.length;
|
|
1364
|
+
return {
|
|
1365
|
+
source: formula,
|
|
1366
|
+
segs: outSegs,
|
|
1367
|
+
slots,
|
|
1368
|
+
uniq,
|
|
1369
|
+
literalLength,
|
|
1370
|
+
rowMin,
|
|
1371
|
+
rowMax,
|
|
1372
|
+
colMin,
|
|
1373
|
+
colMax
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
/** Column letters, cached: shifted references format the same columns over and over. */
|
|
1377
|
+
const LETTERS = [];
|
|
1378
|
+
function letters(n) {
|
|
1379
|
+
return LETTERS[n] ??= colLetters(n);
|
|
1380
|
+
}
|
|
1381
|
+
/** The text of `r` shifted by (dRow, dCol); every relative part must stay on the sheet (canShift). */
|
|
1382
|
+
function refText(r, dRow, dCol) {
|
|
1383
|
+
if (r.kind === COLS_REF) return `${r.aAnchor}${letters(shiftPart(r.aAnchor, r.a, dCol, MAX_COL))}:${r.bAnchor}${letters(shiftPart(r.bAnchor, r.b, dCol, MAX_COL))}`;
|
|
1384
|
+
if (r.kind === ROWS_REF) return `${r.aAnchor}${shiftPart(r.aAnchor, r.a, dRow, MAX_ROW)}:${r.bAnchor}${shiftPart(r.bAnchor, r.b, dRow, MAX_ROW)}`;
|
|
1385
|
+
return `${r.aAnchor}${letters(shiftPart(r.aAnchor, r.a, dCol, MAX_COL))}${r.bAnchor}${shiftPart(r.bAnchor, r.b, dRow, MAX_ROW)}`;
|
|
1386
|
+
}
|
|
1387
|
+
/** Whether every relative reference of `c` stays on the sheet when shifted by (dRow, dCol). Constant time. */
|
|
1388
|
+
function canShift(c, dRow, dCol) {
|
|
1389
|
+
if (dRow === 0 && dCol === 0) return true;
|
|
1390
|
+
if (c.rowMin !== 1e400 && (c.rowMin + dRow < 1 || c.rowMax + dRow > MAX_ROW)) return false;
|
|
1391
|
+
if (c.colMin !== 1e400 && (c.colMin + dCol < 1 || c.colMax + dCol > MAX_COL)) return false;
|
|
1392
|
+
return true;
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* The text of `c` shifted by (dRow, dCol), built once as a flat string; or,
|
|
1396
|
+
* when that text would be longer than `maxLength`, its length (nothing is
|
|
1397
|
+
* built). The caller checks `canShift` first.
|
|
1398
|
+
*/
|
|
1399
|
+
function shiftCompiled(c, dRow, dCol, maxLength = 1e400) {
|
|
1400
|
+
if (dRow === 0 && dCol === 0) return c.source.length > maxLength ? c.source.length : c.source;
|
|
1401
|
+
const { segs, slots, uniq } = c;
|
|
1402
|
+
const texts = [];
|
|
1403
|
+
for (let u = 0; u < uniq.length; u++) texts.push(refText(uniq[u], dRow, dCol));
|
|
1404
|
+
let length = c.literalLength;
|
|
1405
|
+
for (let k = 0; k < slots.length; k++) length += texts[slots[k]].length;
|
|
1406
|
+
if (length > maxLength) return length;
|
|
1407
|
+
const parts = [segs[0]];
|
|
1408
|
+
for (let k = 0; k < slots.length; k++) parts.push(texts[slots[k]], segs[k + 1]);
|
|
1409
|
+
const out = parts.join("");
|
|
1410
|
+
shiftWork.shifts++;
|
|
1411
|
+
shiftWork.shiftedChars += out.length;
|
|
1412
|
+
return out;
|
|
1413
|
+
}
|
|
1414
|
+
/** Whether a reference may end before `end`: no word character, `(`, `!` or `$` follows. */
|
|
1415
|
+
function isEnd(f, end) {
|
|
1416
|
+
if (end >= f.length) return true;
|
|
1417
|
+
const c = f.charCodeAt(end);
|
|
1418
|
+
return !(isWordCode(c) || c === 40 || c === 33 || c === 36);
|
|
1419
|
+
}
|
|
1420
|
+
/** A reference at `i`, or undefined if there is none. Does not depend on the offset. */
|
|
1421
|
+
function parseRef$1(f, i) {
|
|
1422
|
+
const n = f.length;
|
|
1423
|
+
const aAnchor = f.charCodeAt(i) === 36 ? "$" : "";
|
|
1424
|
+
const p = i + aAnchor.length;
|
|
1425
|
+
const la = run(f, p, isLetterCode, 3);
|
|
1426
|
+
const da = la === 0 ? run(f, p, isDigitCode, 7) : 0;
|
|
1427
|
+
const first = la || da;
|
|
1428
|
+
if (first > 0 && f.charCodeAt(p + first) === 58) {
|
|
1429
|
+
const q = p + first + 1;
|
|
1430
|
+
const bAnchor = q < n && f.charCodeAt(q) === 36 ? "$" : "";
|
|
1431
|
+
const r = q + bAnchor.length;
|
|
1432
|
+
const second = run(f, r, la ? isLetterCode : isDigitCode, la ? 3 : 7);
|
|
1433
|
+
if (second > 0 && isEnd(f, r + second)) {
|
|
1434
|
+
if (la) {
|
|
1435
|
+
const a = colNumber(f.slice(p, p + la));
|
|
1436
|
+
const b = colNumber(f.slice(r, r + second));
|
|
1437
|
+
if (a > MAX_COL || b > MAX_COL) return void 0;
|
|
1438
|
+
return {
|
|
1439
|
+
ref: {
|
|
1440
|
+
kind: COLS_REF,
|
|
1441
|
+
aAnchor,
|
|
1442
|
+
a,
|
|
1443
|
+
bAnchor,
|
|
1444
|
+
b
|
|
1445
|
+
},
|
|
1446
|
+
end: r + second
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
return {
|
|
1450
|
+
ref: {
|
|
1451
|
+
kind: ROWS_REF,
|
|
1452
|
+
aAnchor,
|
|
1453
|
+
a: Number(f.slice(p, p + da)),
|
|
1454
|
+
bAnchor,
|
|
1455
|
+
b: Number(f.slice(r, r + second))
|
|
1456
|
+
},
|
|
1457
|
+
end: r + second
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1309
1460
|
}
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
const
|
|
1314
|
-
const
|
|
1315
|
-
if (
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1461
|
+
if (la > 0) {
|
|
1462
|
+
const q = p + la;
|
|
1463
|
+
const bAnchor = f.charCodeAt(q) === 36 ? "$" : "";
|
|
1464
|
+
const r = q + bAnchor.length;
|
|
1465
|
+
const digits = run(f, r, isDigitCode, 7);
|
|
1466
|
+
if (digits > 0 && isEnd(f, r + digits)) {
|
|
1467
|
+
const col = colNumber(f.slice(p, p + la));
|
|
1468
|
+
if (col > MAX_COL) return void 0;
|
|
1469
|
+
return {
|
|
1470
|
+
ref: {
|
|
1471
|
+
kind: CELL_REF,
|
|
1472
|
+
aAnchor,
|
|
1473
|
+
a: col,
|
|
1474
|
+
bAnchor,
|
|
1475
|
+
b: Number(f.slice(r, r + digits))
|
|
1476
|
+
},
|
|
1477
|
+
end: r + digits
|
|
1478
|
+
};
|
|
1479
|
+
}
|
|
1323
1480
|
}
|
|
1324
1481
|
}
|
|
1482
|
+
function isLetterCode(c) {
|
|
1483
|
+
return c >= 65 && c <= 90 || c >= 97 && c <= 122;
|
|
1484
|
+
}
|
|
1485
|
+
function isDigitCode(c) {
|
|
1486
|
+
return c >= 48 && c <= 57;
|
|
1487
|
+
}
|
|
1488
|
+
/** Length of the run of `test` characters at `i`, at most `max` (a longer run then fails on the character after: no pattern accepts it there). */
|
|
1489
|
+
function run(f, i, test, max) {
|
|
1490
|
+
let k = 0;
|
|
1491
|
+
while (k < max && i + k < f.length && test(f.charCodeAt(i + k))) k++;
|
|
1492
|
+
return k;
|
|
1493
|
+
}
|
|
1325
1494
|
function shiftPart(anchor, value, delta, max) {
|
|
1326
1495
|
if (anchor === "$") return value;
|
|
1327
1496
|
const v = value + delta;
|
|
@@ -2200,6 +2369,7 @@ var SheetParser = class {
|
|
|
2200
2369
|
colWork = 0;
|
|
2201
2370
|
merges = [];
|
|
2202
2371
|
hyperlinks = [];
|
|
2372
|
+
/** Shared formula masters by `si`; compiled when the first cell that shares one needs it. */
|
|
2203
2373
|
shared = /* @__PURE__ */ new Map();
|
|
2204
2374
|
view;
|
|
2205
2375
|
print;
|
|
@@ -2626,6 +2796,7 @@ var SheetParser = class {
|
|
|
2626
2796
|
if (p.row < 0) return;
|
|
2627
2797
|
const cell = this.convert(p);
|
|
2628
2798
|
if (!cell) return;
|
|
2799
|
+
if (p.col >= this.ctx.limits.maxColumns) this.tooWide(p.col, p.ref);
|
|
2629
2800
|
this.ctx.countCell();
|
|
2630
2801
|
let row = this.rows[p.row];
|
|
2631
2802
|
if (!row) row = this.rows[p.row] = [];
|
|
@@ -2652,6 +2823,20 @@ var SheetParser = class {
|
|
|
2652
2823
|
if (p.col < this.minCol) this.minCol = p.col;
|
|
2653
2824
|
if (p.col > this.maxCol) this.maxCol = p.col;
|
|
2654
2825
|
}
|
|
2826
|
+
/**
|
|
2827
|
+
* A kept cell in a column past maxColumns (JSE-68). Counted on the cells the
|
|
2828
|
+
* sheet actually has, as each is kept, never on `<dimension>`.
|
|
2829
|
+
*/
|
|
2830
|
+
tooWide(col, ref) {
|
|
2831
|
+
const max = this.ctx.limits.maxColumns;
|
|
2832
|
+
throw new require_errors.LimitError("LIMIT_EXCEEDED", `Sheet "${excerpt(this.sheet.name)}" has a cell in column ${colLetters(col + 1)} (${col + 1}); maxColumns is ${max}.`, { details: {
|
|
2833
|
+
limit: "maxColumns",
|
|
2834
|
+
value: col + 1,
|
|
2835
|
+
max,
|
|
2836
|
+
part: this.part,
|
|
2837
|
+
ref
|
|
2838
|
+
} });
|
|
2839
|
+
}
|
|
2655
2840
|
convert(p) {
|
|
2656
2841
|
const style = this.styles.style(p.s);
|
|
2657
2842
|
let value;
|
|
@@ -2673,6 +2858,7 @@ var SheetParser = class {
|
|
|
2673
2858
|
const sst = this.sharedStrings;
|
|
2674
2859
|
const str = Number.isInteger(idx) && idx >= 0 ? sst[idx] : void 0;
|
|
2675
2860
|
if (str === void 0) {
|
|
2861
|
+
if (p.col >= this.ctx.limits.maxColumns) this.tooWide(p.col, p.ref);
|
|
2676
2862
|
this.ctx.warn("INVALID_SHARED_STRING", `Cell ${p.ref} refers to shared string ${excerpt(v)}, which does not exist; the cell was left empty.`, {
|
|
2677
2863
|
part: this.part,
|
|
2678
2864
|
sheet: this.sheet.name,
|
|
@@ -2776,21 +2962,33 @@ var SheetParser = class {
|
|
|
2776
2962
|
this.shared.set(p.fSi, {
|
|
2777
2963
|
formula: p.f,
|
|
2778
2964
|
row: p.row,
|
|
2779
|
-
col: p.col
|
|
2965
|
+
col: p.col,
|
|
2966
|
+
ref: p.ref,
|
|
2967
|
+
compiled: void 0
|
|
2780
2968
|
});
|
|
2781
2969
|
return { text: p.f };
|
|
2782
2970
|
}
|
|
2783
2971
|
const master = this.shared.get(p.fSi);
|
|
2784
|
-
const
|
|
2785
|
-
if (
|
|
2786
|
-
this.
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2972
|
+
const masterText = this.opts.sharedFormulaText === "master";
|
|
2973
|
+
if (master && !masterText && master.formula.length > 8192) {
|
|
2974
|
+
this.unresolved(p, `: its master formula in cell ${master.ref} has ${master.formula.length} characters, more than Excel's limit of ${MAX_SHARED_FORMULA_LENGTH}`);
|
|
2975
|
+
return;
|
|
2976
|
+
}
|
|
2977
|
+
const dRow = master ? p.row - master.row : 0;
|
|
2978
|
+
const dCol = master ? p.col - master.col : 0;
|
|
2979
|
+
const compiled = master && (dRow !== 0 || dCol !== 0) ? master.compiled ??= compileFormula(master.formula, masterText) : void 0;
|
|
2980
|
+
if (!master || compiled && !canShift(compiled, dRow, dCol)) {
|
|
2981
|
+
this.unresolved(p, "");
|
|
2982
|
+
return;
|
|
2983
|
+
}
|
|
2984
|
+
if (!compiled || masterText) return { text: master.formula };
|
|
2985
|
+
const max = this.ctx.limits.maxCellTextLength;
|
|
2986
|
+
const text = shiftCompiled(compiled, dRow, dCol, max);
|
|
2987
|
+
if (typeof text === "number") {
|
|
2988
|
+
this.unresolved(p, `: shifted, it would have ${text} characters, more than maxCellTextLength (${max})`);
|
|
2791
2989
|
return;
|
|
2792
2990
|
}
|
|
2793
|
-
return { text
|
|
2991
|
+
return { text };
|
|
2794
2992
|
}
|
|
2795
2993
|
if (p.fType === "dataTable") return void 0;
|
|
2796
2994
|
if (p.f === "") return void 0;
|
|
@@ -2800,6 +2998,13 @@ var SheetParser = class {
|
|
|
2800
2998
|
};
|
|
2801
2999
|
return { text: p.f };
|
|
2802
3000
|
}
|
|
3001
|
+
unresolved(p, why) {
|
|
3002
|
+
this.ctx.warn("SHARED_FORMULA_UNRESOLVED", `The shared formula of cell ${p.ref} could not be resolved${why}; only its cached value was read.`, {
|
|
3003
|
+
part: this.part,
|
|
3004
|
+
sheet: this.sheet.name,
|
|
3005
|
+
ref: p.ref
|
|
3006
|
+
});
|
|
3007
|
+
}
|
|
2803
3008
|
/** Set before parsing; the shared strings table. */
|
|
2804
3009
|
sharedStrings = [];
|
|
2805
3010
|
/** When set, shared-string cells are collected here and filled in later (ReadOptions.maxRows). */
|
|
@@ -2951,6 +3156,7 @@ var SheetParser = class {
|
|
|
2951
3156
|
if (!link) return;
|
|
2952
3157
|
const [r, c] = pos;
|
|
2953
3158
|
if (r >= 1048576 || c >= 16384) return;
|
|
3159
|
+
if (c >= this.ctx.limits.maxColumns) this.tooWide(c, `${colLetters(c + 1)}${r + 1}`);
|
|
2954
3160
|
let row = this.rows[r];
|
|
2955
3161
|
if (!row) row = this.rows[r] = [];
|
|
2956
3162
|
const cell = row[c] ?? (row[c] = { type: "empty" });
|
|
@@ -3490,6 +3696,7 @@ async function readImpl(input, options, internal) {
|
|
|
3490
3696
|
const { entry, rel } = listed[i];
|
|
3491
3697
|
const parser = new SheetParser(entry.name, entry.state, ctx, styles, {
|
|
3492
3698
|
formulas: o.formulas !== false,
|
|
3699
|
+
sharedFormulaText: internal?.sharedFormulaText ?? "shifted",
|
|
3493
3700
|
dates: o.dates ?? "date",
|
|
3494
3701
|
dateZone: o.dateZone ?? "local",
|
|
3495
3702
|
richText: o.richText ?? "runs",
|
|
@@ -3677,6 +3884,12 @@ async function read(input, options) {
|
|
|
3677
3884
|
warnings
|
|
3678
3885
|
};
|
|
3679
3886
|
}
|
|
3887
|
+
Object.defineProperty(exports, "DEFAULT_LIMITS", {
|
|
3888
|
+
enumerable: true,
|
|
3889
|
+
get: function() {
|
|
3890
|
+
return DEFAULT_LIMITS;
|
|
3891
|
+
}
|
|
3892
|
+
});
|
|
3680
3893
|
Object.defineProperty(exports, "DEFAULT_READ_LIMITS", {
|
|
3681
3894
|
enumerable: true,
|
|
3682
3895
|
get: function() {
|
|
@@ -3707,6 +3920,12 @@ Object.defineProperty(exports, "read", {
|
|
|
3707
3920
|
return read;
|
|
3708
3921
|
}
|
|
3709
3922
|
});
|
|
3923
|
+
Object.defineProperty(exports, "readImpl", {
|
|
3924
|
+
enumerable: true,
|
|
3925
|
+
get: function() {
|
|
3926
|
+
return readImpl;
|
|
3927
|
+
}
|
|
3928
|
+
});
|
|
3710
3929
|
Object.defineProperty(exports, "readSheetNames", {
|
|
3711
3930
|
enumerable: true,
|
|
3712
3931
|
get: function() {
|