ooxml.js 2.4.0 → 2.5.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 +40 -2
- package/dist/codec.cjs +28 -0
- package/dist/codec.d.cts +72 -0
- package/dist/codec.d.ts +72 -0
- package/dist/codec.js +24 -0
- package/dist/compact.cjs +162 -0
- package/dist/compact.d.cts +70 -0
- package/dist/compact.d.ts +70 -0
- package/dist/compact.js +152 -0
- package/dist/image/sniff.cjs +28 -0
- package/dist/image/sniff.d.cts +5 -0
- package/dist/image/sniff.d.ts +5 -0
- package/dist/image/sniff.js +27 -0
- package/dist/index.cjs +83 -3025
- package/dist/index.d.cts +22 -527
- package/dist/index.d.ts +22 -527
- package/dist/index.js +22 -2964
- package/dist/model/node.cjs +67 -0
- package/dist/model/node.d.cts +2 -0
- package/dist/model/node.d.ts +2 -0
- package/dist/model/node.js +58 -0
- package/dist/model/package.cjs +19 -0
- package/dist/model/package.d.cts +2 -0
- package/dist/model/package.d.ts +2 -0
- package/dist/model/package.js +15 -0
- package/dist/node-CkBWRjNR.d.cts +83 -0
- package/dist/node-CkBWRjNR.d.ts +83 -0
- package/dist/package-BUojjTXf.d.ts +114 -0
- package/dist/package-L24lkba-.d.cts +114 -0
- package/dist/package-io/read.cjs +33 -0
- package/dist/package-io/read.d.cts +5 -0
- package/dist/package-io/read.d.ts +5 -0
- package/dist/package-io/read.js +32 -0
- package/dist/package-io/write.cjs +18 -0
- package/dist/package-io/write.d.cts +5 -0
- package/dist/package-io/write.d.ts +5 -0
- package/dist/package-io/write.js +17 -0
- package/dist/typed/docx/read.cjs +332 -0
- package/dist/typed/docx/read.d.cts +52 -0
- package/dist/typed/docx/read.d.ts +52 -0
- package/dist/typed/docx/read.js +328 -0
- package/dist/typed/docx/styles.cjs +148 -0
- package/dist/typed/docx/styles.d.cts +29 -0
- package/dist/typed/docx/styles.d.ts +29 -0
- package/dist/typed/docx/styles.js +146 -0
- package/dist/typed/pptx/inherit.cjs +96 -0
- package/dist/typed/pptx/inherit.d.cts +30 -0
- package/dist/typed/pptx/inherit.d.ts +30 -0
- package/dist/typed/pptx/inherit.js +90 -0
- package/dist/typed/pptx/read.cjs +364 -0
- package/dist/typed/pptx/read.d.cts +44 -0
- package/dist/typed/pptx/read.d.ts +44 -0
- package/dist/typed/pptx/read.js +362 -0
- package/dist/typed/shared/color.cjs +85 -0
- package/dist/typed/shared/color.d.cts +9 -0
- package/dist/typed/shared/color.d.ts +9 -0
- package/dist/typed/shared/color.js +84 -0
- package/dist/typed/shared/drawingml.cjs +191 -0
- package/dist/typed/shared/drawingml.d.cts +40 -0
- package/dist/typed/shared/drawingml.d.ts +40 -0
- package/dist/typed/shared/drawingml.js +180 -0
- package/dist/typed/shared/metadata.cjs +44 -0
- package/dist/typed/shared/metadata.d.cts +16 -0
- package/dist/typed/shared/metadata.d.ts +16 -0
- package/dist/typed/shared/metadata.js +42 -0
- package/dist/typed/shared/source-path.cjs +18 -0
- package/dist/typed/shared/source-path.d.cts +5 -0
- package/dist/typed/shared/source-path.d.ts +5 -0
- package/dist/typed/shared/source-path.js +17 -0
- package/dist/typed/shared/units.cjs +55 -0
- package/dist/typed/shared/units.d.cts +20 -0
- package/dist/typed/shared/units.d.ts +20 -0
- package/dist/typed/shared/units.js +38 -0
- package/dist/typed/util.cjs +85 -0
- package/dist/typed/util.d.cts +18 -0
- package/dist/typed/util.d.ts +18 -0
- package/dist/typed/util.js +77 -0
- package/dist/typed/xlsx/a1.cjs +64 -0
- package/dist/typed/xlsx/a1.d.cts +19 -0
- package/dist/typed/xlsx/a1.d.ts +19 -0
- package/dist/typed/xlsx/a1.js +58 -0
- package/dist/typed/xlsx/build.cjs +456 -0
- package/dist/typed/xlsx/build.d.cts +6 -0
- package/dist/typed/xlsx/build.d.ts +6 -0
- package/dist/typed/xlsx/build.js +455 -0
- package/dist/typed/xlsx/content.cjs +257 -0
- package/dist/typed/xlsx/content.d.cts +6 -0
- package/dist/typed/xlsx/content.d.ts +6 -0
- package/dist/typed/xlsx/content.js +256 -0
- package/dist/typed/xlsx/defined-names.cjs +90 -0
- package/dist/typed/xlsx/defined-names.d.cts +20 -0
- package/dist/typed/xlsx/defined-names.d.ts +20 -0
- package/dist/typed/xlsx/defined-names.js +83 -0
- package/dist/typed/xlsx/print-settings.cjs +116 -0
- package/dist/typed/xlsx/print-settings.d.cts +8 -0
- package/dist/typed/xlsx/print-settings.d.ts +8 -0
- package/dist/typed/xlsx/print-settings.js +114 -0
- package/dist/typed/xlsx/shared-strings.cjs +35 -0
- package/dist/typed/xlsx/shared-strings.d.cts +12 -0
- package/dist/typed/xlsx/shared-strings.d.ts +12 -0
- package/dist/typed/xlsx/shared-strings.js +33 -0
- package/dist/typed/xlsx/units.cjs +21 -0
- package/dist/typed/xlsx/units.d.cts +8 -0
- package/dist/typed/xlsx/units.d.ts +8 -0
- package/dist/typed/xlsx/units.js +16 -0
- package/dist/typed/xlsx/util.cjs +53 -0
- package/dist/typed/xlsx/util.d.cts +10 -0
- package/dist/typed/xlsx/util.d.ts +10 -0
- package/dist/typed/xlsx/util.js +47 -0
- package/dist/typed/xlsx.cjs +140 -0
- package/dist/typed/xlsx.d.cts +43 -0
- package/dist/typed/xlsx.d.ts +43 -0
- package/dist/typed/xlsx.js +135 -0
- package/dist/util/base64.cjs +48 -0
- package/dist/util/base64.d.cts +5 -0
- package/dist/util/base64.d.ts +5 -0
- package/dist/util/base64.js +46 -0
- package/dist/xml/build.cjs +46 -0
- package/dist/xml/build.d.cts +5 -0
- package/dist/xml/build.d.ts +5 -0
- package/dist/xml/build.js +46 -0
- package/dist/xml/entities.cjs +7 -0
- package/dist/xml/entities.d.cts +4 -0
- package/dist/xml/entities.d.ts +4 -0
- package/dist/xml/entities.js +6 -0
- package/dist/xml/fragment.cjs +22 -0
- package/dist/xml/fragment.d.cts +6 -0
- package/dist/xml/fragment.d.ts +6 -0
- package/dist/xml/fragment.js +20 -0
- package/dist/xml/parse.cjs +88 -0
- package/dist/xml/parse.d.cts +5 -0
- package/dist/xml/parse.d.ts +5 -0
- package/dist/xml/parse.js +88 -0
- package/dist/zip.cjs +12 -0
- package/dist/zip.d.cts +5 -0
- package/dist/zip.d.ts +5 -0
- package/dist/zip.js +10 -0
- package/package.json +9 -1
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_typed_util = require("../util.cjs");
|
|
3
|
+
const require_typed_shared_metadata = require("../shared/metadata.cjs");
|
|
4
|
+
const require_typed_xlsx_shared_strings = require("./shared-strings.cjs");
|
|
5
|
+
const require_typed_xlsx_a1 = require("./a1.cjs");
|
|
6
|
+
const require_typed_xlsx_defined_names = require("./defined-names.cjs");
|
|
7
|
+
const require_typed_xlsx_util = require("./util.cjs");
|
|
8
|
+
const require_typed_xlsx_print_settings = require("./print-settings.cjs");
|
|
9
|
+
const require_typed_xlsx_units = require("./units.cjs");
|
|
10
|
+
let document_schema_js = require("document-schema.js");
|
|
11
|
+
//#region src/typed/xlsx/content.ts
|
|
12
|
+
const WORKBOOK_PATH = "xl/workbook.xml";
|
|
13
|
+
function resolveSheetEntries(pkg) {
|
|
14
|
+
const workbook = require_typed_util.rootElement(pkg.parts[WORKBOOK_PATH]);
|
|
15
|
+
if (workbook === void 0) return [];
|
|
16
|
+
const sheetsEl = require_typed_util.childrenWithTag(workbook, "sheets")[0];
|
|
17
|
+
if (sheetsEl === void 0) return [];
|
|
18
|
+
const rels = require_typed_util.resolveRelationships(pkg, WORKBOOK_PATH);
|
|
19
|
+
const entries = [];
|
|
20
|
+
for (const sheet of require_typed_util.childrenWithTag(sheetsEl, "sheet")) {
|
|
21
|
+
const name = require_typed_util.attr(sheet, "name");
|
|
22
|
+
const rId = require_typed_util.attr(sheet, "r:id");
|
|
23
|
+
const rel = rId === void 0 ? void 0 : rels.get(rId);
|
|
24
|
+
if (name !== void 0 && rel !== void 0) entries.push({
|
|
25
|
+
name,
|
|
26
|
+
path: rel.target
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return entries;
|
|
30
|
+
}
|
|
31
|
+
function sheetFormatDefaultRowHeightPt(worksheet) {
|
|
32
|
+
const sheetFormatPr = require_typed_util.childrenWithTag(worksheet, "sheetFormatPr")[0];
|
|
33
|
+
const raw = sheetFormatPr === void 0 ? void 0 : require_typed_util.attr(sheetFormatPr, "defaultRowHeight");
|
|
34
|
+
if (raw === void 0) return 15;
|
|
35
|
+
const parsed = Number(raw);
|
|
36
|
+
return Number.isFinite(parsed) ? parsed : 15;
|
|
37
|
+
}
|
|
38
|
+
function readColumns(worksheet) {
|
|
39
|
+
const colsEl = require_typed_util.childrenWithTag(worksheet, "cols")[0];
|
|
40
|
+
if (colsEl === void 0) return [];
|
|
41
|
+
const columns = [];
|
|
42
|
+
for (const col of require_typed_util.childrenWithTag(colsEl, "col")) {
|
|
43
|
+
const minRaw = require_typed_util.attr(col, "min");
|
|
44
|
+
const min = minRaw === void 0 ? void 0 : Number.parseInt(minRaw, 10);
|
|
45
|
+
if (min === void 0 || !Number.isInteger(min) || min < 1) continue;
|
|
46
|
+
const widthRaw = require_typed_util.attr(col, "width");
|
|
47
|
+
const widthPt = widthRaw === void 0 ? 0 : require_typed_xlsx_units.columnWidthCharsToPt(Number(widthRaw));
|
|
48
|
+
const column = {
|
|
49
|
+
index: min - 1,
|
|
50
|
+
widthPt: Number.isFinite(widthPt) ? widthPt : 0
|
|
51
|
+
};
|
|
52
|
+
if (require_typed_xlsx_util.readXmlBool(require_typed_util.attr(col, "hidden"))) column.hidden = true;
|
|
53
|
+
columns.push(column);
|
|
54
|
+
}
|
|
55
|
+
return columns;
|
|
56
|
+
}
|
|
57
|
+
function readRows(worksheet) {
|
|
58
|
+
const sheetData = require_typed_util.childrenWithTag(worksheet, "sheetData")[0];
|
|
59
|
+
if (sheetData === void 0) return [];
|
|
60
|
+
const fallbackHeightPt = sheetFormatDefaultRowHeightPt(worksheet);
|
|
61
|
+
const rows = [];
|
|
62
|
+
for (const row of require_typed_util.childrenWithTag(sheetData, "row")) {
|
|
63
|
+
const rRaw = require_typed_util.attr(row, "r");
|
|
64
|
+
const rowNumber = rRaw === void 0 ? void 0 : Number.parseInt(rRaw, 10);
|
|
65
|
+
if (rowNumber === void 0 || !Number.isInteger(rowNumber) || rowNumber < 1) continue;
|
|
66
|
+
const htRaw = require_typed_util.attr(row, "ht");
|
|
67
|
+
const heightPt = htRaw === void 0 ? fallbackHeightPt : Number(htRaw);
|
|
68
|
+
const contentRow = {
|
|
69
|
+
index: rowNumber - 1,
|
|
70
|
+
heightPt: Number.isFinite(heightPt) ? heightPt : fallbackHeightPt
|
|
71
|
+
};
|
|
72
|
+
if (require_typed_xlsx_util.readXmlBool(require_typed_util.attr(row, "hidden"))) contentRow.hidden = true;
|
|
73
|
+
rows.push(contentRow);
|
|
74
|
+
}
|
|
75
|
+
return rows;
|
|
76
|
+
}
|
|
77
|
+
function readInlineOrSharedStringText(container) {
|
|
78
|
+
let value = "";
|
|
79
|
+
for (const t of require_typed_util.elementsWithTag(container.children, "t")) value += require_typed_util.textContent(t);
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
function deriveDisplayText(value) {
|
|
83
|
+
switch (value.kind) {
|
|
84
|
+
case "number": return String(value.value);
|
|
85
|
+
case "boolean": return value.value ? "TRUE" : "FALSE";
|
|
86
|
+
case "string":
|
|
87
|
+
case "error":
|
|
88
|
+
case "date":
|
|
89
|
+
case "time": return value.value;
|
|
90
|
+
case "percentage":
|
|
91
|
+
case "currency": return String(value.value);
|
|
92
|
+
case "empty": return "";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function readCellValue(cell, sharedStrings) {
|
|
96
|
+
const type = require_typed_util.attr(cell, "t");
|
|
97
|
+
if (type === "inlineStr") {
|
|
98
|
+
const is = require_typed_util.childrenWithTag(cell, "is")[0];
|
|
99
|
+
const text = is === void 0 ? void 0 : readInlineOrSharedStringText(is);
|
|
100
|
+
return text === void 0 ? void 0 : {
|
|
101
|
+
value: {
|
|
102
|
+
kind: "string",
|
|
103
|
+
value: text
|
|
104
|
+
},
|
|
105
|
+
displayText: text
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const valueEl = require_typed_util.childrenWithTag(cell, "v")[0];
|
|
109
|
+
const raw = valueEl === void 0 ? void 0 : require_typed_util.textContent(valueEl);
|
|
110
|
+
if (raw === void 0) return;
|
|
111
|
+
if (type === "s") {
|
|
112
|
+
const index = Number.parseInt(raw, 10);
|
|
113
|
+
const text = Number.isInteger(index) ? sharedStrings[index] : void 0;
|
|
114
|
+
return text === void 0 ? void 0 : {
|
|
115
|
+
value: {
|
|
116
|
+
kind: "string",
|
|
117
|
+
value: text
|
|
118
|
+
},
|
|
119
|
+
displayText: text
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (type === "str") return {
|
|
123
|
+
value: {
|
|
124
|
+
kind: "string",
|
|
125
|
+
value: raw
|
|
126
|
+
},
|
|
127
|
+
displayText: raw
|
|
128
|
+
};
|
|
129
|
+
if (type === "b") {
|
|
130
|
+
const value = {
|
|
131
|
+
kind: "boolean",
|
|
132
|
+
value: raw === "1" || raw.toLowerCase() === "true"
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
value,
|
|
136
|
+
displayText: deriveDisplayText(value)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (type === "e") return {
|
|
140
|
+
value: {
|
|
141
|
+
kind: "error",
|
|
142
|
+
value: raw
|
|
143
|
+
},
|
|
144
|
+
displayText: raw
|
|
145
|
+
};
|
|
146
|
+
if (type === "d") return {
|
|
147
|
+
value: {
|
|
148
|
+
kind: "date",
|
|
149
|
+
value: raw
|
|
150
|
+
},
|
|
151
|
+
displayText: raw
|
|
152
|
+
};
|
|
153
|
+
const num = Number(raw);
|
|
154
|
+
if (Number.isNaN(num)) return;
|
|
155
|
+
const value = {
|
|
156
|
+
kind: "number",
|
|
157
|
+
value: num
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
value,
|
|
161
|
+
displayText: deriveDisplayText(value)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function readCell(cell, sharedStrings) {
|
|
165
|
+
const reference = require_typed_util.attr(cell, "r");
|
|
166
|
+
const position = reference === void 0 ? void 0 : require_typed_xlsx_a1.parseCellReference(reference);
|
|
167
|
+
if (position === void 0) return;
|
|
168
|
+
const formulaEl = require_typed_util.childrenWithTag(cell, "f")[0];
|
|
169
|
+
const formula = formulaEl === void 0 ? void 0 : require_typed_util.textContent(formulaEl);
|
|
170
|
+
const resolved = readCellValue(cell, sharedStrings);
|
|
171
|
+
if (resolved === void 0) {
|
|
172
|
+
if (formula === void 0) return;
|
|
173
|
+
return {
|
|
174
|
+
row: position.row,
|
|
175
|
+
column: position.column,
|
|
176
|
+
value: { kind: "empty" },
|
|
177
|
+
formula,
|
|
178
|
+
displayText: ""
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
const cellEntry = {
|
|
182
|
+
row: position.row,
|
|
183
|
+
column: position.column,
|
|
184
|
+
value: resolved.value,
|
|
185
|
+
displayText: resolved.displayText
|
|
186
|
+
};
|
|
187
|
+
if (formula !== void 0) cellEntry.formula = formula;
|
|
188
|
+
return cellEntry;
|
|
189
|
+
}
|
|
190
|
+
function applyMergedRanges(worksheet, cells) {
|
|
191
|
+
const mergeCellsEl = require_typed_util.childrenWithTag(worksheet, "mergeCells")[0];
|
|
192
|
+
if (mergeCellsEl === void 0) return;
|
|
193
|
+
const byPosition = /* @__PURE__ */ new Map();
|
|
194
|
+
for (const cell of cells) byPosition.set(`${cell.row}:${cell.column}`, cell);
|
|
195
|
+
for (const mergeCell of require_typed_util.childrenWithTag(mergeCellsEl, "mergeCell")) {
|
|
196
|
+
const ref = require_typed_util.attr(mergeCell, "ref");
|
|
197
|
+
const range = ref === void 0 ? void 0 : require_typed_xlsx_a1.parseRangeReference(ref);
|
|
198
|
+
if (range === void 0) continue;
|
|
199
|
+
const anchor = byPosition.get(`${range.startRow}:${range.startColumn}`);
|
|
200
|
+
if (anchor === void 0) continue;
|
|
201
|
+
const colSpan = range.endColumn - range.startColumn + 1;
|
|
202
|
+
const rowSpan = range.endRow - range.startRow + 1;
|
|
203
|
+
if (colSpan > 1) anchor.colSpan = colSpan;
|
|
204
|
+
if (rowSpan > 1) anchor.rowSpan = rowSpan;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function readCells(worksheet, sharedStrings) {
|
|
208
|
+
const sheetData = require_typed_util.childrenWithTag(worksheet, "sheetData")[0];
|
|
209
|
+
if (sheetData === void 0) return [];
|
|
210
|
+
const cells = [];
|
|
211
|
+
for (const row of require_typed_util.childrenWithTag(sheetData, "row")) for (const cell of require_typed_util.childrenWithTag(row, "c")) {
|
|
212
|
+
const read = readCell(cell, sharedStrings);
|
|
213
|
+
if (read !== void 0) cells.push(read);
|
|
214
|
+
}
|
|
215
|
+
applyMergedRanges(worksheet, cells);
|
|
216
|
+
return cells;
|
|
217
|
+
}
|
|
218
|
+
function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet) {
|
|
219
|
+
const worksheet = require_typed_util.rootElement(pkg.parts[entry.path]);
|
|
220
|
+
if (worksheet === void 0) return {
|
|
221
|
+
name: entry.name,
|
|
222
|
+
cells: [],
|
|
223
|
+
columns: [],
|
|
224
|
+
rows: [],
|
|
225
|
+
images: [],
|
|
226
|
+
printSettings: require_typed_xlsx_print_settings.readPrintSettings(fallbackEmptyWorksheet(), sheetIndex, definedNamesBySheet)
|
|
227
|
+
};
|
|
228
|
+
return {
|
|
229
|
+
name: entry.name,
|
|
230
|
+
cells: readCells(worksheet, sharedStrings),
|
|
231
|
+
columns: readColumns(worksheet),
|
|
232
|
+
rows: readRows(worksheet),
|
|
233
|
+
images: [],
|
|
234
|
+
printSettings: require_typed_xlsx_print_settings.readPrintSettings(worksheet, sheetIndex, definedNamesBySheet)
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function fallbackEmptyWorksheet() {
|
|
238
|
+
return {
|
|
239
|
+
type: "element",
|
|
240
|
+
tag: "worksheet",
|
|
241
|
+
attributes: [],
|
|
242
|
+
children: []
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function readXlsxContent(pkg) {
|
|
246
|
+
const sharedStrings = require_typed_xlsx_shared_strings.loadSharedStrings(pkg);
|
|
247
|
+
const definedNamesBySheet = require_typed_xlsx_defined_names.readDefinedNamesBySheet(pkg);
|
|
248
|
+
const sheets = resolveSheetEntries(pkg).map((entry, sheetIndex) => readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet));
|
|
249
|
+
return {
|
|
250
|
+
kind: "spreadsheet",
|
|
251
|
+
formatVersion: document_schema_js.CONTENT_FORMAT_VERSION,
|
|
252
|
+
metadata: require_typed_shared_metadata.readCoreProperties(pkg),
|
|
253
|
+
sheets
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
//#endregion
|
|
257
|
+
exports.readXlsxContent = readXlsxContent;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { attr, childrenWithTag, elementsWithTag, resolveRelationships, rootElement, textContent } from "../util.js";
|
|
2
|
+
import { readCoreProperties } from "../shared/metadata.js";
|
|
3
|
+
import { loadSharedStrings } from "./shared-strings.js";
|
|
4
|
+
import { parseCellReference, parseRangeReference } from "./a1.js";
|
|
5
|
+
import { readDefinedNamesBySheet } from "./defined-names.js";
|
|
6
|
+
import { readXmlBool } from "./util.js";
|
|
7
|
+
import { readPrintSettings } from "./print-settings.js";
|
|
8
|
+
import { columnWidthCharsToPt } from "./units.js";
|
|
9
|
+
import { CONTENT_FORMAT_VERSION } from "document-schema.js";
|
|
10
|
+
//#region src/typed/xlsx/content.ts
|
|
11
|
+
const WORKBOOK_PATH = "xl/workbook.xml";
|
|
12
|
+
function resolveSheetEntries(pkg) {
|
|
13
|
+
const workbook = rootElement(pkg.parts[WORKBOOK_PATH]);
|
|
14
|
+
if (workbook === void 0) return [];
|
|
15
|
+
const sheetsEl = childrenWithTag(workbook, "sheets")[0];
|
|
16
|
+
if (sheetsEl === void 0) return [];
|
|
17
|
+
const rels = resolveRelationships(pkg, WORKBOOK_PATH);
|
|
18
|
+
const entries = [];
|
|
19
|
+
for (const sheet of childrenWithTag(sheetsEl, "sheet")) {
|
|
20
|
+
const name = attr(sheet, "name");
|
|
21
|
+
const rId = attr(sheet, "r:id");
|
|
22
|
+
const rel = rId === void 0 ? void 0 : rels.get(rId);
|
|
23
|
+
if (name !== void 0 && rel !== void 0) entries.push({
|
|
24
|
+
name,
|
|
25
|
+
path: rel.target
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return entries;
|
|
29
|
+
}
|
|
30
|
+
function sheetFormatDefaultRowHeightPt(worksheet) {
|
|
31
|
+
const sheetFormatPr = childrenWithTag(worksheet, "sheetFormatPr")[0];
|
|
32
|
+
const raw = sheetFormatPr === void 0 ? void 0 : attr(sheetFormatPr, "defaultRowHeight");
|
|
33
|
+
if (raw === void 0) return 15;
|
|
34
|
+
const parsed = Number(raw);
|
|
35
|
+
return Number.isFinite(parsed) ? parsed : 15;
|
|
36
|
+
}
|
|
37
|
+
function readColumns(worksheet) {
|
|
38
|
+
const colsEl = childrenWithTag(worksheet, "cols")[0];
|
|
39
|
+
if (colsEl === void 0) return [];
|
|
40
|
+
const columns = [];
|
|
41
|
+
for (const col of childrenWithTag(colsEl, "col")) {
|
|
42
|
+
const minRaw = attr(col, "min");
|
|
43
|
+
const min = minRaw === void 0 ? void 0 : Number.parseInt(minRaw, 10);
|
|
44
|
+
if (min === void 0 || !Number.isInteger(min) || min < 1) continue;
|
|
45
|
+
const widthRaw = attr(col, "width");
|
|
46
|
+
const widthPt = widthRaw === void 0 ? 0 : columnWidthCharsToPt(Number(widthRaw));
|
|
47
|
+
const column = {
|
|
48
|
+
index: min - 1,
|
|
49
|
+
widthPt: Number.isFinite(widthPt) ? widthPt : 0
|
|
50
|
+
};
|
|
51
|
+
if (readXmlBool(attr(col, "hidden"))) column.hidden = true;
|
|
52
|
+
columns.push(column);
|
|
53
|
+
}
|
|
54
|
+
return columns;
|
|
55
|
+
}
|
|
56
|
+
function readRows(worksheet) {
|
|
57
|
+
const sheetData = childrenWithTag(worksheet, "sheetData")[0];
|
|
58
|
+
if (sheetData === void 0) return [];
|
|
59
|
+
const fallbackHeightPt = sheetFormatDefaultRowHeightPt(worksheet);
|
|
60
|
+
const rows = [];
|
|
61
|
+
for (const row of childrenWithTag(sheetData, "row")) {
|
|
62
|
+
const rRaw = attr(row, "r");
|
|
63
|
+
const rowNumber = rRaw === void 0 ? void 0 : Number.parseInt(rRaw, 10);
|
|
64
|
+
if (rowNumber === void 0 || !Number.isInteger(rowNumber) || rowNumber < 1) continue;
|
|
65
|
+
const htRaw = attr(row, "ht");
|
|
66
|
+
const heightPt = htRaw === void 0 ? fallbackHeightPt : Number(htRaw);
|
|
67
|
+
const contentRow = {
|
|
68
|
+
index: rowNumber - 1,
|
|
69
|
+
heightPt: Number.isFinite(heightPt) ? heightPt : fallbackHeightPt
|
|
70
|
+
};
|
|
71
|
+
if (readXmlBool(attr(row, "hidden"))) contentRow.hidden = true;
|
|
72
|
+
rows.push(contentRow);
|
|
73
|
+
}
|
|
74
|
+
return rows;
|
|
75
|
+
}
|
|
76
|
+
function readInlineOrSharedStringText(container) {
|
|
77
|
+
let value = "";
|
|
78
|
+
for (const t of elementsWithTag(container.children, "t")) value += textContent(t);
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
function deriveDisplayText(value) {
|
|
82
|
+
switch (value.kind) {
|
|
83
|
+
case "number": return String(value.value);
|
|
84
|
+
case "boolean": return value.value ? "TRUE" : "FALSE";
|
|
85
|
+
case "string":
|
|
86
|
+
case "error":
|
|
87
|
+
case "date":
|
|
88
|
+
case "time": return value.value;
|
|
89
|
+
case "percentage":
|
|
90
|
+
case "currency": return String(value.value);
|
|
91
|
+
case "empty": return "";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function readCellValue(cell, sharedStrings) {
|
|
95
|
+
const type = attr(cell, "t");
|
|
96
|
+
if (type === "inlineStr") {
|
|
97
|
+
const is = childrenWithTag(cell, "is")[0];
|
|
98
|
+
const text = is === void 0 ? void 0 : readInlineOrSharedStringText(is);
|
|
99
|
+
return text === void 0 ? void 0 : {
|
|
100
|
+
value: {
|
|
101
|
+
kind: "string",
|
|
102
|
+
value: text
|
|
103
|
+
},
|
|
104
|
+
displayText: text
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const valueEl = childrenWithTag(cell, "v")[0];
|
|
108
|
+
const raw = valueEl === void 0 ? void 0 : textContent(valueEl);
|
|
109
|
+
if (raw === void 0) return;
|
|
110
|
+
if (type === "s") {
|
|
111
|
+
const index = Number.parseInt(raw, 10);
|
|
112
|
+
const text = Number.isInteger(index) ? sharedStrings[index] : void 0;
|
|
113
|
+
return text === void 0 ? void 0 : {
|
|
114
|
+
value: {
|
|
115
|
+
kind: "string",
|
|
116
|
+
value: text
|
|
117
|
+
},
|
|
118
|
+
displayText: text
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (type === "str") return {
|
|
122
|
+
value: {
|
|
123
|
+
kind: "string",
|
|
124
|
+
value: raw
|
|
125
|
+
},
|
|
126
|
+
displayText: raw
|
|
127
|
+
};
|
|
128
|
+
if (type === "b") {
|
|
129
|
+
const value = {
|
|
130
|
+
kind: "boolean",
|
|
131
|
+
value: raw === "1" || raw.toLowerCase() === "true"
|
|
132
|
+
};
|
|
133
|
+
return {
|
|
134
|
+
value,
|
|
135
|
+
displayText: deriveDisplayText(value)
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (type === "e") return {
|
|
139
|
+
value: {
|
|
140
|
+
kind: "error",
|
|
141
|
+
value: raw
|
|
142
|
+
},
|
|
143
|
+
displayText: raw
|
|
144
|
+
};
|
|
145
|
+
if (type === "d") return {
|
|
146
|
+
value: {
|
|
147
|
+
kind: "date",
|
|
148
|
+
value: raw
|
|
149
|
+
},
|
|
150
|
+
displayText: raw
|
|
151
|
+
};
|
|
152
|
+
const num = Number(raw);
|
|
153
|
+
if (Number.isNaN(num)) return;
|
|
154
|
+
const value = {
|
|
155
|
+
kind: "number",
|
|
156
|
+
value: num
|
|
157
|
+
};
|
|
158
|
+
return {
|
|
159
|
+
value,
|
|
160
|
+
displayText: deriveDisplayText(value)
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function readCell(cell, sharedStrings) {
|
|
164
|
+
const reference = attr(cell, "r");
|
|
165
|
+
const position = reference === void 0 ? void 0 : parseCellReference(reference);
|
|
166
|
+
if (position === void 0) return;
|
|
167
|
+
const formulaEl = childrenWithTag(cell, "f")[0];
|
|
168
|
+
const formula = formulaEl === void 0 ? void 0 : textContent(formulaEl);
|
|
169
|
+
const resolved = readCellValue(cell, sharedStrings);
|
|
170
|
+
if (resolved === void 0) {
|
|
171
|
+
if (formula === void 0) return;
|
|
172
|
+
return {
|
|
173
|
+
row: position.row,
|
|
174
|
+
column: position.column,
|
|
175
|
+
value: { kind: "empty" },
|
|
176
|
+
formula,
|
|
177
|
+
displayText: ""
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const cellEntry = {
|
|
181
|
+
row: position.row,
|
|
182
|
+
column: position.column,
|
|
183
|
+
value: resolved.value,
|
|
184
|
+
displayText: resolved.displayText
|
|
185
|
+
};
|
|
186
|
+
if (formula !== void 0) cellEntry.formula = formula;
|
|
187
|
+
return cellEntry;
|
|
188
|
+
}
|
|
189
|
+
function applyMergedRanges(worksheet, cells) {
|
|
190
|
+
const mergeCellsEl = childrenWithTag(worksheet, "mergeCells")[0];
|
|
191
|
+
if (mergeCellsEl === void 0) return;
|
|
192
|
+
const byPosition = /* @__PURE__ */ new Map();
|
|
193
|
+
for (const cell of cells) byPosition.set(`${cell.row}:${cell.column}`, cell);
|
|
194
|
+
for (const mergeCell of childrenWithTag(mergeCellsEl, "mergeCell")) {
|
|
195
|
+
const ref = attr(mergeCell, "ref");
|
|
196
|
+
const range = ref === void 0 ? void 0 : parseRangeReference(ref);
|
|
197
|
+
if (range === void 0) continue;
|
|
198
|
+
const anchor = byPosition.get(`${range.startRow}:${range.startColumn}`);
|
|
199
|
+
if (anchor === void 0) continue;
|
|
200
|
+
const colSpan = range.endColumn - range.startColumn + 1;
|
|
201
|
+
const rowSpan = range.endRow - range.startRow + 1;
|
|
202
|
+
if (colSpan > 1) anchor.colSpan = colSpan;
|
|
203
|
+
if (rowSpan > 1) anchor.rowSpan = rowSpan;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function readCells(worksheet, sharedStrings) {
|
|
207
|
+
const sheetData = childrenWithTag(worksheet, "sheetData")[0];
|
|
208
|
+
if (sheetData === void 0) return [];
|
|
209
|
+
const cells = [];
|
|
210
|
+
for (const row of childrenWithTag(sheetData, "row")) for (const cell of childrenWithTag(row, "c")) {
|
|
211
|
+
const read = readCell(cell, sharedStrings);
|
|
212
|
+
if (read !== void 0) cells.push(read);
|
|
213
|
+
}
|
|
214
|
+
applyMergedRanges(worksheet, cells);
|
|
215
|
+
return cells;
|
|
216
|
+
}
|
|
217
|
+
function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet) {
|
|
218
|
+
const worksheet = rootElement(pkg.parts[entry.path]);
|
|
219
|
+
if (worksheet === void 0) return {
|
|
220
|
+
name: entry.name,
|
|
221
|
+
cells: [],
|
|
222
|
+
columns: [],
|
|
223
|
+
rows: [],
|
|
224
|
+
images: [],
|
|
225
|
+
printSettings: readPrintSettings(fallbackEmptyWorksheet(), sheetIndex, definedNamesBySheet)
|
|
226
|
+
};
|
|
227
|
+
return {
|
|
228
|
+
name: entry.name,
|
|
229
|
+
cells: readCells(worksheet, sharedStrings),
|
|
230
|
+
columns: readColumns(worksheet),
|
|
231
|
+
rows: readRows(worksheet),
|
|
232
|
+
images: [],
|
|
233
|
+
printSettings: readPrintSettings(worksheet, sheetIndex, definedNamesBySheet)
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function fallbackEmptyWorksheet() {
|
|
237
|
+
return {
|
|
238
|
+
type: "element",
|
|
239
|
+
tag: "worksheet",
|
|
240
|
+
attributes: [],
|
|
241
|
+
children: []
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function readXlsxContent(pkg) {
|
|
245
|
+
const sharedStrings = loadSharedStrings(pkg);
|
|
246
|
+
const definedNamesBySheet = readDefinedNamesBySheet(pkg);
|
|
247
|
+
const sheets = resolveSheetEntries(pkg).map((entry, sheetIndex) => readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet));
|
|
248
|
+
return {
|
|
249
|
+
kind: "spreadsheet",
|
|
250
|
+
formatVersion: CONTENT_FORMAT_VERSION,
|
|
251
|
+
metadata: readCoreProperties(pkg),
|
|
252
|
+
sheets
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
//#endregion
|
|
256
|
+
export { readXlsxContent };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_typed_util = require("../util.cjs");
|
|
3
|
+
const require_typed_xlsx_a1 = require("./a1.cjs");
|
|
4
|
+
//#region src/typed/xlsx/defined-names.ts
|
|
5
|
+
const XLNM_PRINT_AREA = "_xlnm.Print_Area";
|
|
6
|
+
const XLNM_PRINT_TITLES = "_xlnm.Print_Titles";
|
|
7
|
+
function readDefinedNamesBySheet(pkg) {
|
|
8
|
+
const map = /* @__PURE__ */ new Map();
|
|
9
|
+
const workbook = require_typed_util.rootElement(pkg.parts["xl/workbook.xml"]);
|
|
10
|
+
if (workbook === void 0) return map;
|
|
11
|
+
const container = require_typed_util.childrenWithTag(workbook, "definedNames")[0];
|
|
12
|
+
if (container === void 0) return map;
|
|
13
|
+
for (const definedName of require_typed_util.childrenWithTag(container, "definedName")) {
|
|
14
|
+
const name = require_typed_util.attr(definedName, "name");
|
|
15
|
+
const localSheetIdRaw = require_typed_util.attr(definedName, "localSheetId");
|
|
16
|
+
if (name === void 0 || localSheetIdRaw === void 0) continue;
|
|
17
|
+
if (name !== "_xlnm.Print_Area" && name !== "_xlnm.Print_Titles") continue;
|
|
18
|
+
const sheetIndex = Number.parseInt(localSheetIdRaw, 10);
|
|
19
|
+
if (!Number.isInteger(sheetIndex) || sheetIndex < 0) continue;
|
|
20
|
+
const value = require_typed_util.textContent(definedName);
|
|
21
|
+
const existing = map.get(sheetIndex) ?? {};
|
|
22
|
+
if (name === "_xlnm.Print_Area") existing.printArea = value;
|
|
23
|
+
else existing.printTitles = value;
|
|
24
|
+
map.set(sheetIndex, existing);
|
|
25
|
+
}
|
|
26
|
+
return map;
|
|
27
|
+
}
|
|
28
|
+
function stripSheetPrefix(segment) {
|
|
29
|
+
const bang = segment.lastIndexOf("!");
|
|
30
|
+
return bang === -1 ? segment : segment.slice(bang + 1);
|
|
31
|
+
}
|
|
32
|
+
function parsePrintAreaValue(value) {
|
|
33
|
+
const first = value.split(",")[0]?.trim();
|
|
34
|
+
if (first === void 0 || first.length === 0) return;
|
|
35
|
+
return require_typed_xlsx_a1.parseRangeReference(stripSheetPrefix(first).replace(/\$/g, ""));
|
|
36
|
+
}
|
|
37
|
+
function parsePrintTitlesValue(value) {
|
|
38
|
+
const result = {};
|
|
39
|
+
for (const rawSegment of value.split(",")) {
|
|
40
|
+
const segment = stripSheetPrefix(rawSegment.trim()).replace(/\$/g, "");
|
|
41
|
+
const separatorIndex = segment.indexOf(":");
|
|
42
|
+
if (separatorIndex === -1) continue;
|
|
43
|
+
const startSpec = segment.slice(0, separatorIndex);
|
|
44
|
+
const endSpec = segment.slice(separatorIndex + 1);
|
|
45
|
+
if (/^[A-Za-z]+$/.test(startSpec) && /^[A-Za-z]+$/.test(endSpec)) {
|
|
46
|
+
const start = require_typed_xlsx_a1.columnLettersToIndex(startSpec);
|
|
47
|
+
const end = require_typed_xlsx_a1.columnLettersToIndex(endSpec);
|
|
48
|
+
if (start !== void 0 && end !== void 0) result.repeatColumns = {
|
|
49
|
+
start: Math.min(start, end),
|
|
50
|
+
end: Math.max(start, end)
|
|
51
|
+
};
|
|
52
|
+
} else if (/^\d+$/.test(startSpec) && /^\d+$/.test(endSpec)) {
|
|
53
|
+
const start = Number.parseInt(startSpec, 10) - 1;
|
|
54
|
+
const end = Number.parseInt(endSpec, 10) - 1;
|
|
55
|
+
result.repeatRows = {
|
|
56
|
+
start: Math.min(start, end),
|
|
57
|
+
end: Math.max(start, end)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
function quoteSheetNameIfNeeded(sheetName) {
|
|
64
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(sheetName)) return sheetName;
|
|
65
|
+
return `'${sheetName.replace(/'/g, "''")}'`;
|
|
66
|
+
}
|
|
67
|
+
function buildPrintAreaValue(sheetName, range) {
|
|
68
|
+
const dollared = require_typed_xlsx_a1.rangeReference({
|
|
69
|
+
startRow: range.startRow,
|
|
70
|
+
startColumn: range.startColumn,
|
|
71
|
+
endRow: range.endRow,
|
|
72
|
+
endColumn: range.endColumn
|
|
73
|
+
}).replace(/([A-Z]+)(\d+)/g, "$$$1$$$2");
|
|
74
|
+
return `${quoteSheetNameIfNeeded(sheetName)}!${dollared}`;
|
|
75
|
+
}
|
|
76
|
+
function buildPrintTitlesValue(sheetName, repeatRows, repeatColumns) {
|
|
77
|
+
const quotedName = quoteSheetNameIfNeeded(sheetName);
|
|
78
|
+
const segments = [];
|
|
79
|
+
if (repeatColumns !== void 0) segments.push(`${quotedName}!$${require_typed_xlsx_a1.columnIndexToLetters(repeatColumns.start)}:$${require_typed_xlsx_a1.columnIndexToLetters(repeatColumns.end)}`);
|
|
80
|
+
if (repeatRows !== void 0) segments.push(`${quotedName}!$${repeatRows.start + 1}:$${repeatRows.end + 1}`);
|
|
81
|
+
return segments.length > 0 ? segments.join(",") : void 0;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
exports.XLNM_PRINT_AREA = XLNM_PRINT_AREA;
|
|
85
|
+
exports.XLNM_PRINT_TITLES = XLNM_PRINT_TITLES;
|
|
86
|
+
exports.buildPrintAreaValue = buildPrintAreaValue;
|
|
87
|
+
exports.buildPrintTitlesValue = buildPrintTitlesValue;
|
|
88
|
+
exports.parsePrintAreaValue = parsePrintAreaValue;
|
|
89
|
+
exports.parsePrintTitlesValue = parsePrintTitlesValue;
|
|
90
|
+
exports.readDefinedNamesBySheet = readDefinedNamesBySheet;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { r as Package } from "../../package-L24lkba-.cjs";
|
|
2
|
+
import { ContentSheetPrintRange, ContentSheetRepeatRange } from "document-schema.js";
|
|
3
|
+
//#region src/typed/xlsx/defined-names.d.ts
|
|
4
|
+
interface SheetDefinedNames {
|
|
5
|
+
printArea?: string;
|
|
6
|
+
printTitles?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const XLNM_PRINT_AREA = "_xlnm.Print_Area";
|
|
9
|
+
declare const XLNM_PRINT_TITLES = "_xlnm.Print_Titles";
|
|
10
|
+
declare function readDefinedNamesBySheet(pkg: Package): Map<number, SheetDefinedNames>;
|
|
11
|
+
declare function parsePrintAreaValue(value: string): ContentSheetPrintRange | undefined;
|
|
12
|
+
interface PrintTitles {
|
|
13
|
+
repeatRows?: ContentSheetRepeatRange;
|
|
14
|
+
repeatColumns?: ContentSheetRepeatRange;
|
|
15
|
+
}
|
|
16
|
+
declare function parsePrintTitlesValue(value: string): PrintTitles;
|
|
17
|
+
declare function buildPrintAreaValue(sheetName: string, range: ContentSheetPrintRange): string;
|
|
18
|
+
declare function buildPrintTitlesValue(sheetName: string, repeatRows: ContentSheetRepeatRange | undefined, repeatColumns: ContentSheetRepeatRange | undefined): string | undefined;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { SheetDefinedNames, XLNM_PRINT_AREA, XLNM_PRINT_TITLES, buildPrintAreaValue, buildPrintTitlesValue, parsePrintAreaValue, parsePrintTitlesValue, readDefinedNamesBySheet };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { r as Package } from "../../package-BUojjTXf.js";
|
|
2
|
+
import { ContentSheetPrintRange, ContentSheetRepeatRange } from "document-schema.js";
|
|
3
|
+
//#region src/typed/xlsx/defined-names.d.ts
|
|
4
|
+
interface SheetDefinedNames {
|
|
5
|
+
printArea?: string;
|
|
6
|
+
printTitles?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const XLNM_PRINT_AREA = "_xlnm.Print_Area";
|
|
9
|
+
declare const XLNM_PRINT_TITLES = "_xlnm.Print_Titles";
|
|
10
|
+
declare function readDefinedNamesBySheet(pkg: Package): Map<number, SheetDefinedNames>;
|
|
11
|
+
declare function parsePrintAreaValue(value: string): ContentSheetPrintRange | undefined;
|
|
12
|
+
interface PrintTitles {
|
|
13
|
+
repeatRows?: ContentSheetRepeatRange;
|
|
14
|
+
repeatColumns?: ContentSheetRepeatRange;
|
|
15
|
+
}
|
|
16
|
+
declare function parsePrintTitlesValue(value: string): PrintTitles;
|
|
17
|
+
declare function buildPrintAreaValue(sheetName: string, range: ContentSheetPrintRange): string;
|
|
18
|
+
declare function buildPrintTitlesValue(sheetName: string, repeatRows: ContentSheetRepeatRange | undefined, repeatColumns: ContentSheetRepeatRange | undefined): string | undefined;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { SheetDefinedNames, XLNM_PRINT_AREA, XLNM_PRINT_TITLES, buildPrintAreaValue, buildPrintTitlesValue, parsePrintAreaValue, parsePrintTitlesValue, readDefinedNamesBySheet };
|