ooxml.js 2.1.1 → 2.2.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/dist/index.cjs +1130 -24
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +1061 -26
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -311,6 +311,30 @@ function encodePackage(pkg) {
|
|
|
311
311
|
return zod.z.encode(packageCodec, pkg);
|
|
312
312
|
}
|
|
313
313
|
//#endregion
|
|
314
|
+
//#region src/xml/fragment.ts
|
|
315
|
+
function el(tag, attrs = {}, children = []) {
|
|
316
|
+
return {
|
|
317
|
+
type: "element",
|
|
318
|
+
tag,
|
|
319
|
+
attributes: Object.entries(attrs).map(([name, value]) => ({
|
|
320
|
+
name,
|
|
321
|
+
value
|
|
322
|
+
})),
|
|
323
|
+
children
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
function txt(value) {
|
|
327
|
+
return {
|
|
328
|
+
type: "text",
|
|
329
|
+
value
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/xml/entities.ts
|
|
334
|
+
function encodeXmlText(value) {
|
|
335
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
336
|
+
}
|
|
337
|
+
//#endregion
|
|
314
338
|
//#region src/typed/util.ts
|
|
315
339
|
function* walk(nodes) {
|
|
316
340
|
for (const node of nodes) {
|
|
@@ -1053,13 +1077,13 @@ const DOCUMENT_PART_PATH = "word/document.xml";
|
|
|
1053
1077
|
const STYLES_PART_PATH = "word/styles.xml";
|
|
1054
1078
|
const THEME_REL_SUFFIX$1 = "/theme";
|
|
1055
1079
|
const DEFAULT_MARGIN_PT = 72;
|
|
1056
|
-
const DEFAULT_MARGINS = {
|
|
1080
|
+
const DEFAULT_MARGINS$1 = {
|
|
1057
1081
|
topPt: DEFAULT_MARGIN_PT,
|
|
1058
1082
|
rightPt: DEFAULT_MARGIN_PT,
|
|
1059
1083
|
bottomPt: DEFAULT_MARGIN_PT,
|
|
1060
1084
|
leftPt: DEFAULT_MARGIN_PT
|
|
1061
1085
|
};
|
|
1062
|
-
function readPageSize(sectPr) {
|
|
1086
|
+
function readPageSize$1(sectPr) {
|
|
1063
1087
|
const pgSz = childrenWithTag(sectPr, "w:pgSz")[0];
|
|
1064
1088
|
const w = pgSz === void 0 ? void 0 : attr(pgSz, "w:w");
|
|
1065
1089
|
const h = pgSz === void 0 ? void 0 : attr(pgSz, "w:h");
|
|
@@ -1068,9 +1092,9 @@ function readPageSize(sectPr) {
|
|
|
1068
1092
|
heightPt: twipsToPt(Number(h))
|
|
1069
1093
|
};
|
|
1070
1094
|
}
|
|
1071
|
-
function readMargins(sectPr) {
|
|
1095
|
+
function readMargins$1(sectPr) {
|
|
1072
1096
|
const pgMar = childrenWithTag(sectPr, "w:pgMar")[0];
|
|
1073
|
-
if (pgMar === void 0) return DEFAULT_MARGINS;
|
|
1097
|
+
if (pgMar === void 0) return DEFAULT_MARGINS$1;
|
|
1074
1098
|
const top = attr(pgMar, "w:top");
|
|
1075
1099
|
const right = attr(pgMar, "w:right");
|
|
1076
1100
|
const bottom = attr(pgMar, "w:bottom");
|
|
@@ -1254,8 +1278,8 @@ function readSections(body, context, rels) {
|
|
|
1254
1278
|
if (node.type !== "element") continue;
|
|
1255
1279
|
if (node.tag === "w:sectPr") {
|
|
1256
1280
|
sections.push({
|
|
1257
|
-
pageSize: readPageSize(node),
|
|
1258
|
-
margins: readMargins(node),
|
|
1281
|
+
pageSize: readPageSize$1(node),
|
|
1282
|
+
margins: readMargins$1(node),
|
|
1259
1283
|
blocks: currentBlocks
|
|
1260
1284
|
});
|
|
1261
1285
|
currentBlocks = [];
|
|
@@ -1268,8 +1292,8 @@ function readSections(body, context, rels) {
|
|
|
1268
1292
|
currentBlocks.push(readParagraph$1(node, context, rels));
|
|
1269
1293
|
if (sectPr !== void 0) {
|
|
1270
1294
|
sections.push({
|
|
1271
|
-
pageSize: readPageSize(sectPr),
|
|
1272
|
-
margins: readMargins(sectPr),
|
|
1295
|
+
pageSize: readPageSize$1(sectPr),
|
|
1296
|
+
margins: readMargins$1(sectPr),
|
|
1273
1297
|
blocks: currentBlocks
|
|
1274
1298
|
});
|
|
1275
1299
|
currentBlocks = [];
|
|
@@ -1280,7 +1304,7 @@ function readSections(body, context, rels) {
|
|
|
1280
1304
|
}
|
|
1281
1305
|
if (currentBlocks.length > 0 || sections.length === 0) sections.push({
|
|
1282
1306
|
pageSize: document_content_model.PAGE_SIZE_LETTER,
|
|
1283
|
-
margins: DEFAULT_MARGINS,
|
|
1307
|
+
margins: DEFAULT_MARGINS$1,
|
|
1284
1308
|
blocks: currentBlocks
|
|
1285
1309
|
});
|
|
1286
1310
|
sections.forEach((section, sectionIndex) => assignSourcePaths(section.blocks, `sections[${sectionIndex}]`));
|
|
@@ -1788,6 +1812,37 @@ function readPptx(pkg) {
|
|
|
1788
1812
|
};
|
|
1789
1813
|
}
|
|
1790
1814
|
//#endregion
|
|
1815
|
+
//#region src/typed/xlsx/shared-strings.ts
|
|
1816
|
+
function loadSharedStrings(pkg) {
|
|
1817
|
+
const root = rootElement(pkg.parts["xl/sharedStrings.xml"]);
|
|
1818
|
+
if (root === void 0) return [];
|
|
1819
|
+
const strings = [];
|
|
1820
|
+
for (const si of childrenWithTag(root, "si")) {
|
|
1821
|
+
let value = "";
|
|
1822
|
+
for (const t of elementsWithTag(si.children, "t")) value += textContent(t);
|
|
1823
|
+
strings.push(value);
|
|
1824
|
+
}
|
|
1825
|
+
return strings;
|
|
1826
|
+
}
|
|
1827
|
+
var SharedStringTable = class {
|
|
1828
|
+
indexByValue = /* @__PURE__ */ new Map();
|
|
1829
|
+
values = [];
|
|
1830
|
+
intern(value) {
|
|
1831
|
+
const existing = this.indexByValue.get(value);
|
|
1832
|
+
if (existing !== void 0) return existing;
|
|
1833
|
+
const index = this.values.length;
|
|
1834
|
+
this.indexByValue.set(value, index);
|
|
1835
|
+
this.values.push(value);
|
|
1836
|
+
return index;
|
|
1837
|
+
}
|
|
1838
|
+
entries() {
|
|
1839
|
+
return this.values;
|
|
1840
|
+
}
|
|
1841
|
+
get size() {
|
|
1842
|
+
return this.values.length;
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
//#endregion
|
|
1791
1846
|
//#region src/typed/xlsx.ts
|
|
1792
1847
|
const XlsxCellSchema = zod.z.object({
|
|
1793
1848
|
reference: zod.z.string(),
|
|
@@ -1808,17 +1863,6 @@ const XlsxWorkbookSchema = zod.z.object({
|
|
|
1808
1863
|
definedNames: zod.z.array(DefinedNameSchema)
|
|
1809
1864
|
});
|
|
1810
1865
|
const SHEET_PATH_RE = /^xl\/worksheets\/sheet(\d+)\.xml$/;
|
|
1811
|
-
function loadSharedStrings(pkg) {
|
|
1812
|
-
const root = rootElement(pkg.parts["xl/sharedStrings.xml"]);
|
|
1813
|
-
if (root === void 0) return [];
|
|
1814
|
-
const strings = [];
|
|
1815
|
-
for (const si of childrenWithTag(root, "si")) {
|
|
1816
|
-
let value = "";
|
|
1817
|
-
for (const t of elementsWithTag(si.children, "t")) value += textContent(t);
|
|
1818
|
-
strings.push(value);
|
|
1819
|
-
}
|
|
1820
|
-
return strings;
|
|
1821
|
-
}
|
|
1822
1866
|
function resolveRelTarget(target) {
|
|
1823
1867
|
if (target.startsWith("/")) return target.slice(1);
|
|
1824
1868
|
return `xl/${target}`;
|
|
@@ -1869,7 +1913,7 @@ function sheetNumberOf(path) {
|
|
|
1869
1913
|
if (digits === void 0) return;
|
|
1870
1914
|
return Number.parseInt(digits, 10);
|
|
1871
1915
|
}
|
|
1872
|
-
function readCell(cell, sharedStrings) {
|
|
1916
|
+
function readCell$1(cell, sharedStrings) {
|
|
1873
1917
|
const reference = attr(cell, "r");
|
|
1874
1918
|
if (reference === void 0) return;
|
|
1875
1919
|
const valueEl = childrenWithTag(cell, "v")[0];
|
|
@@ -1889,10 +1933,10 @@ function readCell(cell, sharedStrings) {
|
|
|
1889
1933
|
if (formulaEl !== void 0) projected.formula = textContent(formulaEl);
|
|
1890
1934
|
return projected;
|
|
1891
1935
|
}
|
|
1892
|
-
function readCells(worksheet, sharedStrings) {
|
|
1936
|
+
function readCells$1(worksheet, sharedStrings) {
|
|
1893
1937
|
const cells = [];
|
|
1894
1938
|
for (const row of elementsWithTag(worksheet.children, "row")) for (const cell of childrenWithTag(row, "c")) {
|
|
1895
|
-
const projected = readCell(cell, sharedStrings);
|
|
1939
|
+
const projected = readCell$1(cell, sharedStrings);
|
|
1896
1940
|
if (projected !== void 0) cells.push(projected);
|
|
1897
1941
|
}
|
|
1898
1942
|
return cells;
|
|
@@ -1920,7 +1964,7 @@ function readXlsx(pkg) {
|
|
|
1920
1964
|
const name = names.get(path) ?? `Sheet${number}`;
|
|
1921
1965
|
sheets.push({
|
|
1922
1966
|
name,
|
|
1923
|
-
cells: readCells(root, sharedStrings),
|
|
1967
|
+
cells: readCells$1(root, sharedStrings),
|
|
1924
1968
|
mergedRanges: readMergedRanges(root)
|
|
1925
1969
|
});
|
|
1926
1970
|
}
|
|
@@ -1930,6 +1974,997 @@ function readXlsx(pkg) {
|
|
|
1930
1974
|
};
|
|
1931
1975
|
}
|
|
1932
1976
|
//#endregion
|
|
1977
|
+
//#region src/typed/xlsx/a1.ts
|
|
1978
|
+
const CELL_REFERENCE_RE = /^([A-Za-z]+)(\d+)$/;
|
|
1979
|
+
function columnLettersToIndex(letters) {
|
|
1980
|
+
if (letters.length === 0) return;
|
|
1981
|
+
let index = 0;
|
|
1982
|
+
for (const ch of letters.toUpperCase()) {
|
|
1983
|
+
const code = ch.charCodeAt(0);
|
|
1984
|
+
if (code < 65 || code > 90) return;
|
|
1985
|
+
index = index * 26 + (code - 64);
|
|
1986
|
+
}
|
|
1987
|
+
return index - 1;
|
|
1988
|
+
}
|
|
1989
|
+
function columnIndexToLetters(index) {
|
|
1990
|
+
let remaining = index + 1;
|
|
1991
|
+
let letters = "";
|
|
1992
|
+
while (remaining > 0) {
|
|
1993
|
+
const digit = (remaining - 1) % 26;
|
|
1994
|
+
letters = String.fromCharCode(65 + digit) + letters;
|
|
1995
|
+
remaining = Math.trunc((remaining - 1) / 26);
|
|
1996
|
+
}
|
|
1997
|
+
return letters;
|
|
1998
|
+
}
|
|
1999
|
+
function parseCellReference(ref) {
|
|
2000
|
+
const match = CELL_REFERENCE_RE.exec(ref);
|
|
2001
|
+
if (match === null) return;
|
|
2002
|
+
const letters = match[1];
|
|
2003
|
+
const digits = match[2];
|
|
2004
|
+
if (letters === void 0 || digits === void 0) return;
|
|
2005
|
+
const column = columnLettersToIndex(letters);
|
|
2006
|
+
const rowNumber = Number.parseInt(digits, 10);
|
|
2007
|
+
if (column === void 0 || !Number.isInteger(rowNumber) || rowNumber < 1) return;
|
|
2008
|
+
return {
|
|
2009
|
+
row: rowNumber - 1,
|
|
2010
|
+
column
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
function cellReference(row, column) {
|
|
2014
|
+
return `${columnIndexToLetters(column)}${row + 1}`;
|
|
2015
|
+
}
|
|
2016
|
+
function parseRangeReference(ref) {
|
|
2017
|
+
const separatorIndex = ref.indexOf(":");
|
|
2018
|
+
const startRaw = separatorIndex === -1 ? ref : ref.slice(0, separatorIndex);
|
|
2019
|
+
const endRaw = separatorIndex === -1 ? ref : ref.slice(separatorIndex + 1);
|
|
2020
|
+
const start = parseCellReference(startRaw);
|
|
2021
|
+
const end = parseCellReference(endRaw);
|
|
2022
|
+
if (start === void 0 || end === void 0) return;
|
|
2023
|
+
return {
|
|
2024
|
+
startRow: Math.min(start.row, end.row),
|
|
2025
|
+
startColumn: Math.min(start.column, end.column),
|
|
2026
|
+
endRow: Math.max(start.row, end.row),
|
|
2027
|
+
endColumn: Math.max(start.column, end.column)
|
|
2028
|
+
};
|
|
2029
|
+
}
|
|
2030
|
+
function rangeReference(range) {
|
|
2031
|
+
return `${cellReference(range.startRow, range.startColumn)}:${cellReference(range.endRow, range.endColumn)}`;
|
|
2032
|
+
}
|
|
2033
|
+
//#endregion
|
|
2034
|
+
//#region src/typed/xlsx/defined-names.ts
|
|
2035
|
+
const PRINT_AREA_NAME = "_xlnm.Print_Area";
|
|
2036
|
+
const PRINT_TITLES_NAME = "_xlnm.Print_Titles";
|
|
2037
|
+
function readDefinedNamesBySheet(pkg) {
|
|
2038
|
+
const map = /* @__PURE__ */ new Map();
|
|
2039
|
+
const workbook = rootElement(pkg.parts["xl/workbook.xml"]);
|
|
2040
|
+
if (workbook === void 0) return map;
|
|
2041
|
+
const container = childrenWithTag(workbook, "definedNames")[0];
|
|
2042
|
+
if (container === void 0) return map;
|
|
2043
|
+
for (const definedName of childrenWithTag(container, "definedName")) {
|
|
2044
|
+
const name = attr(definedName, "name");
|
|
2045
|
+
const localSheetIdRaw = attr(definedName, "localSheetId");
|
|
2046
|
+
if (name === void 0 || localSheetIdRaw === void 0) continue;
|
|
2047
|
+
if (name !== PRINT_AREA_NAME && name !== PRINT_TITLES_NAME) continue;
|
|
2048
|
+
const sheetIndex = Number.parseInt(localSheetIdRaw, 10);
|
|
2049
|
+
if (!Number.isInteger(sheetIndex) || sheetIndex < 0) continue;
|
|
2050
|
+
const value = textContent(definedName);
|
|
2051
|
+
const existing = map.get(sheetIndex) ?? {};
|
|
2052
|
+
if (name === PRINT_AREA_NAME) existing.printArea = value;
|
|
2053
|
+
else existing.printTitles = value;
|
|
2054
|
+
map.set(sheetIndex, existing);
|
|
2055
|
+
}
|
|
2056
|
+
return map;
|
|
2057
|
+
}
|
|
2058
|
+
function stripSheetPrefix(segment) {
|
|
2059
|
+
const bang = segment.lastIndexOf("!");
|
|
2060
|
+
return bang === -1 ? segment : segment.slice(bang + 1);
|
|
2061
|
+
}
|
|
2062
|
+
function parsePrintAreaValue(value) {
|
|
2063
|
+
const first = value.split(",")[0]?.trim();
|
|
2064
|
+
if (first === void 0 || first.length === 0) return;
|
|
2065
|
+
return parseRangeReference(stripSheetPrefix(first).replace(/\$/g, ""));
|
|
2066
|
+
}
|
|
2067
|
+
function parsePrintTitlesValue(value) {
|
|
2068
|
+
const result = {};
|
|
2069
|
+
for (const rawSegment of value.split(",")) {
|
|
2070
|
+
const segment = stripSheetPrefix(rawSegment.trim()).replace(/\$/g, "");
|
|
2071
|
+
const separatorIndex = segment.indexOf(":");
|
|
2072
|
+
if (separatorIndex === -1) continue;
|
|
2073
|
+
const startSpec = segment.slice(0, separatorIndex);
|
|
2074
|
+
const endSpec = segment.slice(separatorIndex + 1);
|
|
2075
|
+
if (/^[A-Za-z]+$/.test(startSpec) && /^[A-Za-z]+$/.test(endSpec)) {
|
|
2076
|
+
const start = columnLettersToIndex(startSpec);
|
|
2077
|
+
const end = columnLettersToIndex(endSpec);
|
|
2078
|
+
if (start !== void 0 && end !== void 0) result.repeatColumns = {
|
|
2079
|
+
start: Math.min(start, end),
|
|
2080
|
+
end: Math.max(start, end)
|
|
2081
|
+
};
|
|
2082
|
+
} else if (/^\d+$/.test(startSpec) && /^\d+$/.test(endSpec)) {
|
|
2083
|
+
const start = Number.parseInt(startSpec, 10) - 1;
|
|
2084
|
+
const end = Number.parseInt(endSpec, 10) - 1;
|
|
2085
|
+
result.repeatRows = {
|
|
2086
|
+
start: Math.min(start, end),
|
|
2087
|
+
end: Math.max(start, end)
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
return result;
|
|
2092
|
+
}
|
|
2093
|
+
function quoteSheetNameIfNeeded(sheetName) {
|
|
2094
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(sheetName)) return sheetName;
|
|
2095
|
+
return `'${sheetName.replace(/'/g, "''")}'`;
|
|
2096
|
+
}
|
|
2097
|
+
function buildPrintAreaValue(sheetName, range) {
|
|
2098
|
+
const dollared = rangeReference({
|
|
2099
|
+
startRow: range.startRow,
|
|
2100
|
+
startColumn: range.startColumn,
|
|
2101
|
+
endRow: range.endRow,
|
|
2102
|
+
endColumn: range.endColumn
|
|
2103
|
+
}).replace(/([A-Z]+)(\d+)/g, "$$$1$$$2");
|
|
2104
|
+
return `${quoteSheetNameIfNeeded(sheetName)}!${dollared}`;
|
|
2105
|
+
}
|
|
2106
|
+
function buildPrintTitlesValue(sheetName, repeatRows, repeatColumns) {
|
|
2107
|
+
const quotedName = quoteSheetNameIfNeeded(sheetName);
|
|
2108
|
+
const segments = [];
|
|
2109
|
+
if (repeatColumns !== void 0) segments.push(`${quotedName}!$${columnIndexToLetters(repeatColumns.start)}:$${columnIndexToLetters(repeatColumns.end)}`);
|
|
2110
|
+
if (repeatRows !== void 0) segments.push(`${quotedName}!$${repeatRows.start + 1}:$${repeatRows.end + 1}`);
|
|
2111
|
+
return segments.length > 0 ? segments.join(",") : void 0;
|
|
2112
|
+
}
|
|
2113
|
+
const XLNM_PRINT_AREA = PRINT_AREA_NAME;
|
|
2114
|
+
const XLNM_PRINT_TITLES = PRINT_TITLES_NAME;
|
|
2115
|
+
//#endregion
|
|
2116
|
+
//#region src/typed/xlsx/util.ts
|
|
2117
|
+
function readXmlBool(value) {
|
|
2118
|
+
return value === "1" || value === "true";
|
|
2119
|
+
}
|
|
2120
|
+
function writeXmlBool(value) {
|
|
2121
|
+
return value ? "true" : "false";
|
|
2122
|
+
}
|
|
2123
|
+
const UNIVERSAL_MEASURE_RE = /^(-?\d+(?:\.\d+)?)(mm|cm|in|pt|pc|pi)$/;
|
|
2124
|
+
function parseUniversalMeasureToPt(value) {
|
|
2125
|
+
const match = UNIVERSAL_MEASURE_RE.exec(value.trim());
|
|
2126
|
+
if (match === null) return;
|
|
2127
|
+
const amountRaw = match[1];
|
|
2128
|
+
const unit = match[2];
|
|
2129
|
+
if (amountRaw === void 0 || unit === void 0) return;
|
|
2130
|
+
const amount = Number(amountRaw);
|
|
2131
|
+
switch (unit) {
|
|
2132
|
+
case "mm": return amount / 25.4 * 72;
|
|
2133
|
+
case "cm": return amount / 2.54 * 72;
|
|
2134
|
+
case "in": return amount * 72;
|
|
2135
|
+
case "pt": return amount;
|
|
2136
|
+
case "pc":
|
|
2137
|
+
case "pi": return amount * 12;
|
|
2138
|
+
default: return;
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
function ptToUniversalMeasure(pt) {
|
|
2142
|
+
return `${(pt / 72 * 2.54).toFixed(2)}cm`;
|
|
2143
|
+
}
|
|
2144
|
+
const PAPER_SIZE_BY_CODE = {
|
|
2145
|
+
"1": document_content_model.PAGE_SIZE_LETTER,
|
|
2146
|
+
"9": document_content_model.PAGE_SIZE_A4
|
|
2147
|
+
};
|
|
2148
|
+
function paperSizeCodeToPageSize(code) {
|
|
2149
|
+
return PAPER_SIZE_BY_CODE[code];
|
|
2150
|
+
}
|
|
2151
|
+
const PAPER_SIZE_TOLERANCE_PT = .5;
|
|
2152
|
+
function approximatelyEquals(a, b) {
|
|
2153
|
+
return Math.abs(a - b) <= PAPER_SIZE_TOLERANCE_PT;
|
|
2154
|
+
}
|
|
2155
|
+
function pageSizeToPaperSizeCode(pageSize) {
|
|
2156
|
+
if (approximatelyEquals(pageSize.widthPt, document_content_model.PAGE_SIZE_LETTER.widthPt) && approximatelyEquals(pageSize.heightPt, document_content_model.PAGE_SIZE_LETTER.heightPt)) return "1";
|
|
2157
|
+
if (approximatelyEquals(pageSize.widthPt, document_content_model.PAGE_SIZE_A4.widthPt) && approximatelyEquals(pageSize.heightPt, document_content_model.PAGE_SIZE_A4.heightPt)) return "9";
|
|
2158
|
+
}
|
|
2159
|
+
//#endregion
|
|
2160
|
+
//#region src/typed/xlsx/print-settings.ts
|
|
2161
|
+
const DEFAULT_MARGINS = {
|
|
2162
|
+
topPt: .75 * 72,
|
|
2163
|
+
rightPt: .7 * 72,
|
|
2164
|
+
bottomPt: .75 * 72,
|
|
2165
|
+
leftPt: .7 * 72
|
|
2166
|
+
};
|
|
2167
|
+
const DEFAULT_HEADER_FOOTER_MARGIN_PT = .3 * 72;
|
|
2168
|
+
const DEFAULT_FIT_TO_PAGES = 1;
|
|
2169
|
+
function applyOrientation(pageSize, pageSetup) {
|
|
2170
|
+
if ((pageSetup === void 0 ? void 0 : attr(pageSetup, "orientation")) !== "landscape") return pageSize;
|
|
2171
|
+
return {
|
|
2172
|
+
widthPt: pageSize.heightPt,
|
|
2173
|
+
heightPt: pageSize.widthPt
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
function readPageSize(pageSetup) {
|
|
2177
|
+
if (pageSetup === void 0) return document_content_model.PAGE_SIZE_LETTER;
|
|
2178
|
+
const paperSize = attr(pageSetup, "paperSize");
|
|
2179
|
+
const byCode = paperSize === void 0 ? void 0 : paperSizeCodeToPageSize(paperSize);
|
|
2180
|
+
if (byCode !== void 0) return applyOrientation(byCode, pageSetup);
|
|
2181
|
+
const paperWidth = attr(pageSetup, "paperWidth");
|
|
2182
|
+
const paperHeight = attr(pageSetup, "paperHeight");
|
|
2183
|
+
const widthPt = paperWidth === void 0 ? void 0 : parseUniversalMeasureToPt(paperWidth);
|
|
2184
|
+
const heightPt = paperHeight === void 0 ? void 0 : parseUniversalMeasureToPt(paperHeight);
|
|
2185
|
+
return widthPt === void 0 || heightPt === void 0 ? document_content_model.PAGE_SIZE_LETTER : applyOrientation({
|
|
2186
|
+
widthPt,
|
|
2187
|
+
heightPt
|
|
2188
|
+
}, pageSetup);
|
|
2189
|
+
}
|
|
2190
|
+
function readMargins(pageMargins) {
|
|
2191
|
+
if (pageMargins === void 0) return DEFAULT_MARGINS;
|
|
2192
|
+
const top = attr(pageMargins, "top");
|
|
2193
|
+
const right = attr(pageMargins, "right");
|
|
2194
|
+
const bottom = attr(pageMargins, "bottom");
|
|
2195
|
+
const left = attr(pageMargins, "left");
|
|
2196
|
+
return {
|
|
2197
|
+
topPt: top === void 0 ? DEFAULT_MARGINS.topPt : Number(top) * 72,
|
|
2198
|
+
rightPt: right === void 0 ? DEFAULT_MARGINS.rightPt : Number(right) * 72,
|
|
2199
|
+
bottomPt: bottom === void 0 ? DEFAULT_MARGINS.bottomPt : Number(bottom) * 72,
|
|
2200
|
+
leftPt: left === void 0 ? DEFAULT_MARGINS.leftPt : Number(left) * 72
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
function readPageOrder(pageSetup) {
|
|
2204
|
+
return (pageSetup === void 0 ? void 0 : attr(pageSetup, "pageOrder")) === "overThenDown" ? "overThenDown" : "downThenOver";
|
|
2205
|
+
}
|
|
2206
|
+
function readManualBreaks(worksheet) {
|
|
2207
|
+
const rowBreaksEl = childrenWithTag(worksheet, "rowBreaks")[0];
|
|
2208
|
+
const colBreaksEl = childrenWithTag(worksheet, "colBreaks")[0];
|
|
2209
|
+
const rows = rowBreaksEl === void 0 ? [] : readBreakIndices(rowBreaksEl);
|
|
2210
|
+
const columns = colBreaksEl === void 0 ? [] : readBreakIndices(colBreaksEl);
|
|
2211
|
+
return rows.length > 0 || columns.length > 0 ? {
|
|
2212
|
+
rows,
|
|
2213
|
+
columns
|
|
2214
|
+
} : void 0;
|
|
2215
|
+
}
|
|
2216
|
+
function readBreakIndices(container) {
|
|
2217
|
+
const indices = [];
|
|
2218
|
+
for (const brk of childrenWithTag(container, "brk")) {
|
|
2219
|
+
const id = attr(brk, "id");
|
|
2220
|
+
const index = id === void 0 ? void 0 : Number.parseInt(id, 10);
|
|
2221
|
+
if (index !== void 0 && Number.isInteger(index) && index >= 0) indices.push(index);
|
|
2222
|
+
}
|
|
2223
|
+
return indices;
|
|
2224
|
+
}
|
|
2225
|
+
function readPrintSettings(worksheet, sheetIndex, definedNamesBySheet) {
|
|
2226
|
+
const sheetPr = childrenWithTag(worksheet, "sheetPr")[0];
|
|
2227
|
+
const pageSetUpPr = sheetPr === void 0 ? void 0 : childrenWithTag(sheetPr, "pageSetUpPr")[0];
|
|
2228
|
+
const fitToPage = readXmlBool(pageSetUpPr === void 0 ? void 0 : attr(pageSetUpPr, "fitToPage"));
|
|
2229
|
+
const pageSetup = childrenWithTag(worksheet, "pageSetup")[0];
|
|
2230
|
+
const pageMargins = childrenWithTag(worksheet, "pageMargins")[0];
|
|
2231
|
+
const printOptions = childrenWithTag(worksheet, "printOptions")[0];
|
|
2232
|
+
const manualBreaks = readManualBreaks(worksheet);
|
|
2233
|
+
const definedNames = definedNamesBySheet.get(sheetIndex);
|
|
2234
|
+
const settings = {
|
|
2235
|
+
pageSize: readPageSize(pageSetup),
|
|
2236
|
+
margins: readMargins(pageMargins),
|
|
2237
|
+
gridlines: readXmlBool(printOptions === void 0 ? void 0 : attr(printOptions, "gridLines")),
|
|
2238
|
+
headers: readXmlBool(printOptions === void 0 ? void 0 : attr(printOptions, "headings")),
|
|
2239
|
+
pageOrder: readPageOrder(pageSetup)
|
|
2240
|
+
};
|
|
2241
|
+
if (fitToPage) {
|
|
2242
|
+
const fitToWidthRaw = pageSetup === void 0 ? void 0 : attr(pageSetup, "fitToWidth");
|
|
2243
|
+
const fitToHeightRaw = pageSetup === void 0 ? void 0 : attr(pageSetup, "fitToHeight");
|
|
2244
|
+
settings.fitToPages = {
|
|
2245
|
+
width: fitToWidthRaw === void 0 ? DEFAULT_FIT_TO_PAGES : Number(fitToWidthRaw),
|
|
2246
|
+
height: fitToHeightRaw === void 0 ? DEFAULT_FIT_TO_PAGES : Number(fitToHeightRaw)
|
|
2247
|
+
};
|
|
2248
|
+
} else {
|
|
2249
|
+
const scaleRaw = pageSetup === void 0 ? void 0 : attr(pageSetup, "scale");
|
|
2250
|
+
if (scaleRaw !== void 0) {
|
|
2251
|
+
const scale = Number(scaleRaw);
|
|
2252
|
+
if (Number.isFinite(scale)) settings.scale = scale;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
if (manualBreaks !== void 0) settings.manualBreaks = manualBreaks;
|
|
2256
|
+
if (definedNames?.printArea !== void 0) {
|
|
2257
|
+
const range = parsePrintAreaValue(definedNames.printArea);
|
|
2258
|
+
if (range !== void 0) settings.printRange = range;
|
|
2259
|
+
}
|
|
2260
|
+
if (definedNames?.printTitles !== void 0) {
|
|
2261
|
+
const titles = parsePrintTitlesValue(definedNames.printTitles);
|
|
2262
|
+
if (titles.repeatRows !== void 0) settings.repeatRows = titles.repeatRows;
|
|
2263
|
+
if (titles.repeatColumns !== void 0) settings.repeatColumns = titles.repeatColumns;
|
|
2264
|
+
}
|
|
2265
|
+
return settings;
|
|
2266
|
+
}
|
|
2267
|
+
function columnWidthCharsToPt(width) {
|
|
2268
|
+
const digitWidthAllowance = Math.trunc(128 / 7);
|
|
2269
|
+
return Math.trunc((256 * width + digitWidthAllowance) / 256 * 7) / 96 * 72;
|
|
2270
|
+
}
|
|
2271
|
+
function ptToColumnWidthChars(widthPt) {
|
|
2272
|
+
const pixels = widthPt / 72 * 96;
|
|
2273
|
+
const digitWidthAllowance = Math.trunc(128 / 7);
|
|
2274
|
+
return pixels / 7 - digitWidthAllowance / 256;
|
|
2275
|
+
}
|
|
2276
|
+
//#endregion
|
|
2277
|
+
//#region src/typed/xlsx/content.ts
|
|
2278
|
+
const WORKBOOK_PATH = "xl/workbook.xml";
|
|
2279
|
+
function resolveSheetEntries(pkg) {
|
|
2280
|
+
const workbook = rootElement(pkg.parts[WORKBOOK_PATH]);
|
|
2281
|
+
if (workbook === void 0) return [];
|
|
2282
|
+
const sheetsEl = childrenWithTag(workbook, "sheets")[0];
|
|
2283
|
+
if (sheetsEl === void 0) return [];
|
|
2284
|
+
const rels = resolveRelationships(pkg, WORKBOOK_PATH);
|
|
2285
|
+
const entries = [];
|
|
2286
|
+
for (const sheet of childrenWithTag(sheetsEl, "sheet")) {
|
|
2287
|
+
const name = attr(sheet, "name");
|
|
2288
|
+
const rId = attr(sheet, "r:id");
|
|
2289
|
+
const rel = rId === void 0 ? void 0 : rels.get(rId);
|
|
2290
|
+
if (name !== void 0 && rel !== void 0) entries.push({
|
|
2291
|
+
name,
|
|
2292
|
+
path: rel.target
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
return entries;
|
|
2296
|
+
}
|
|
2297
|
+
function sheetFormatDefaultRowHeightPt(worksheet) {
|
|
2298
|
+
const sheetFormatPr = childrenWithTag(worksheet, "sheetFormatPr")[0];
|
|
2299
|
+
const raw = sheetFormatPr === void 0 ? void 0 : attr(sheetFormatPr, "defaultRowHeight");
|
|
2300
|
+
if (raw === void 0) return 15;
|
|
2301
|
+
const parsed = Number(raw);
|
|
2302
|
+
return Number.isFinite(parsed) ? parsed : 15;
|
|
2303
|
+
}
|
|
2304
|
+
function readColumns(worksheet) {
|
|
2305
|
+
const colsEl = childrenWithTag(worksheet, "cols")[0];
|
|
2306
|
+
if (colsEl === void 0) return [];
|
|
2307
|
+
const columns = [];
|
|
2308
|
+
for (const col of childrenWithTag(colsEl, "col")) {
|
|
2309
|
+
const minRaw = attr(col, "min");
|
|
2310
|
+
const min = minRaw === void 0 ? void 0 : Number.parseInt(minRaw, 10);
|
|
2311
|
+
if (min === void 0 || !Number.isInteger(min) || min < 1) continue;
|
|
2312
|
+
const widthRaw = attr(col, "width");
|
|
2313
|
+
const widthPt = widthRaw === void 0 ? 0 : columnWidthCharsToPt(Number(widthRaw));
|
|
2314
|
+
const column = {
|
|
2315
|
+
index: min - 1,
|
|
2316
|
+
widthPt: Number.isFinite(widthPt) ? widthPt : 0
|
|
2317
|
+
};
|
|
2318
|
+
if (readXmlBool(attr(col, "hidden"))) column.hidden = true;
|
|
2319
|
+
columns.push(column);
|
|
2320
|
+
}
|
|
2321
|
+
return columns;
|
|
2322
|
+
}
|
|
2323
|
+
function readRows(worksheet) {
|
|
2324
|
+
const sheetData = childrenWithTag(worksheet, "sheetData")[0];
|
|
2325
|
+
if (sheetData === void 0) return [];
|
|
2326
|
+
const fallbackHeightPt = sheetFormatDefaultRowHeightPt(worksheet);
|
|
2327
|
+
const rows = [];
|
|
2328
|
+
for (const row of childrenWithTag(sheetData, "row")) {
|
|
2329
|
+
const rRaw = attr(row, "r");
|
|
2330
|
+
const rowNumber = rRaw === void 0 ? void 0 : Number.parseInt(rRaw, 10);
|
|
2331
|
+
if (rowNumber === void 0 || !Number.isInteger(rowNumber) || rowNumber < 1) continue;
|
|
2332
|
+
const htRaw = attr(row, "ht");
|
|
2333
|
+
const heightPt = htRaw === void 0 ? fallbackHeightPt : Number(htRaw);
|
|
2334
|
+
const contentRow = {
|
|
2335
|
+
index: rowNumber - 1,
|
|
2336
|
+
heightPt: Number.isFinite(heightPt) ? heightPt : fallbackHeightPt
|
|
2337
|
+
};
|
|
2338
|
+
if (readXmlBool(attr(row, "hidden"))) contentRow.hidden = true;
|
|
2339
|
+
rows.push(contentRow);
|
|
2340
|
+
}
|
|
2341
|
+
return rows;
|
|
2342
|
+
}
|
|
2343
|
+
function readInlineOrSharedStringText(container) {
|
|
2344
|
+
let value = "";
|
|
2345
|
+
for (const t of elementsWithTag(container.children, "t")) value += textContent(t);
|
|
2346
|
+
return value;
|
|
2347
|
+
}
|
|
2348
|
+
function deriveDisplayText(value) {
|
|
2349
|
+
switch (value.kind) {
|
|
2350
|
+
case "number": return String(value.value);
|
|
2351
|
+
case "boolean": return value.value ? "TRUE" : "FALSE";
|
|
2352
|
+
case "string":
|
|
2353
|
+
case "error":
|
|
2354
|
+
case "date":
|
|
2355
|
+
case "time": return value.value;
|
|
2356
|
+
case "percentage":
|
|
2357
|
+
case "currency": return String(value.value);
|
|
2358
|
+
case "empty": return "";
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
function readCellValue(cell, sharedStrings) {
|
|
2362
|
+
const type = attr(cell, "t");
|
|
2363
|
+
if (type === "inlineStr") {
|
|
2364
|
+
const is = childrenWithTag(cell, "is")[0];
|
|
2365
|
+
const text = is === void 0 ? void 0 : readInlineOrSharedStringText(is);
|
|
2366
|
+
return text === void 0 ? void 0 : {
|
|
2367
|
+
value: {
|
|
2368
|
+
kind: "string",
|
|
2369
|
+
value: text
|
|
2370
|
+
},
|
|
2371
|
+
displayText: text
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
const valueEl = childrenWithTag(cell, "v")[0];
|
|
2375
|
+
const raw = valueEl === void 0 ? void 0 : textContent(valueEl);
|
|
2376
|
+
if (raw === void 0) return;
|
|
2377
|
+
if (type === "s") {
|
|
2378
|
+
const index = Number.parseInt(raw, 10);
|
|
2379
|
+
const text = Number.isInteger(index) ? sharedStrings[index] : void 0;
|
|
2380
|
+
return text === void 0 ? void 0 : {
|
|
2381
|
+
value: {
|
|
2382
|
+
kind: "string",
|
|
2383
|
+
value: text
|
|
2384
|
+
},
|
|
2385
|
+
displayText: text
|
|
2386
|
+
};
|
|
2387
|
+
}
|
|
2388
|
+
if (type === "str") return {
|
|
2389
|
+
value: {
|
|
2390
|
+
kind: "string",
|
|
2391
|
+
value: raw
|
|
2392
|
+
},
|
|
2393
|
+
displayText: raw
|
|
2394
|
+
};
|
|
2395
|
+
if (type === "b") {
|
|
2396
|
+
const value = {
|
|
2397
|
+
kind: "boolean",
|
|
2398
|
+
value: raw === "1" || raw.toLowerCase() === "true"
|
|
2399
|
+
};
|
|
2400
|
+
return {
|
|
2401
|
+
value,
|
|
2402
|
+
displayText: deriveDisplayText(value)
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
if (type === "e") return {
|
|
2406
|
+
value: {
|
|
2407
|
+
kind: "error",
|
|
2408
|
+
value: raw
|
|
2409
|
+
},
|
|
2410
|
+
displayText: raw
|
|
2411
|
+
};
|
|
2412
|
+
if (type === "d") return {
|
|
2413
|
+
value: {
|
|
2414
|
+
kind: "date",
|
|
2415
|
+
value: raw
|
|
2416
|
+
},
|
|
2417
|
+
displayText: raw
|
|
2418
|
+
};
|
|
2419
|
+
const num = Number(raw);
|
|
2420
|
+
if (Number.isNaN(num)) return;
|
|
2421
|
+
const value = {
|
|
2422
|
+
kind: "number",
|
|
2423
|
+
value: num
|
|
2424
|
+
};
|
|
2425
|
+
return {
|
|
2426
|
+
value,
|
|
2427
|
+
displayText: deriveDisplayText(value)
|
|
2428
|
+
};
|
|
2429
|
+
}
|
|
2430
|
+
function readCell(cell, sharedStrings) {
|
|
2431
|
+
const reference = attr(cell, "r");
|
|
2432
|
+
const position = reference === void 0 ? void 0 : parseCellReference(reference);
|
|
2433
|
+
if (position === void 0) return;
|
|
2434
|
+
const formulaEl = childrenWithTag(cell, "f")[0];
|
|
2435
|
+
const formula = formulaEl === void 0 ? void 0 : textContent(formulaEl);
|
|
2436
|
+
const resolved = readCellValue(cell, sharedStrings);
|
|
2437
|
+
if (resolved === void 0) {
|
|
2438
|
+
if (formula === void 0) return;
|
|
2439
|
+
return {
|
|
2440
|
+
row: position.row,
|
|
2441
|
+
column: position.column,
|
|
2442
|
+
value: { kind: "empty" },
|
|
2443
|
+
formula,
|
|
2444
|
+
displayText: ""
|
|
2445
|
+
};
|
|
2446
|
+
}
|
|
2447
|
+
const cellEntry = {
|
|
2448
|
+
row: position.row,
|
|
2449
|
+
column: position.column,
|
|
2450
|
+
value: resolved.value,
|
|
2451
|
+
displayText: resolved.displayText
|
|
2452
|
+
};
|
|
2453
|
+
if (formula !== void 0) cellEntry.formula = formula;
|
|
2454
|
+
return cellEntry;
|
|
2455
|
+
}
|
|
2456
|
+
function applyMergedRanges(worksheet, cells) {
|
|
2457
|
+
const mergeCellsEl = childrenWithTag(worksheet, "mergeCells")[0];
|
|
2458
|
+
if (mergeCellsEl === void 0) return;
|
|
2459
|
+
const byPosition = /* @__PURE__ */ new Map();
|
|
2460
|
+
for (const cell of cells) byPosition.set(`${cell.row}:${cell.column}`, cell);
|
|
2461
|
+
for (const mergeCell of childrenWithTag(mergeCellsEl, "mergeCell")) {
|
|
2462
|
+
const ref = attr(mergeCell, "ref");
|
|
2463
|
+
const range = ref === void 0 ? void 0 : parseRangeReference(ref);
|
|
2464
|
+
if (range === void 0) continue;
|
|
2465
|
+
const anchor = byPosition.get(`${range.startRow}:${range.startColumn}`);
|
|
2466
|
+
if (anchor === void 0) continue;
|
|
2467
|
+
const colSpan = range.endColumn - range.startColumn + 1;
|
|
2468
|
+
const rowSpan = range.endRow - range.startRow + 1;
|
|
2469
|
+
if (colSpan > 1) anchor.colSpan = colSpan;
|
|
2470
|
+
if (rowSpan > 1) anchor.rowSpan = rowSpan;
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
function readCells(worksheet, sharedStrings) {
|
|
2474
|
+
const sheetData = childrenWithTag(worksheet, "sheetData")[0];
|
|
2475
|
+
if (sheetData === void 0) return [];
|
|
2476
|
+
const cells = [];
|
|
2477
|
+
for (const row of childrenWithTag(sheetData, "row")) for (const cell of childrenWithTag(row, "c")) {
|
|
2478
|
+
const read = readCell(cell, sharedStrings);
|
|
2479
|
+
if (read !== void 0) cells.push(read);
|
|
2480
|
+
}
|
|
2481
|
+
applyMergedRanges(worksheet, cells);
|
|
2482
|
+
return cells;
|
|
2483
|
+
}
|
|
2484
|
+
function readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet) {
|
|
2485
|
+
const worksheet = rootElement(pkg.parts[entry.path]);
|
|
2486
|
+
if (worksheet === void 0) return {
|
|
2487
|
+
name: entry.name,
|
|
2488
|
+
cells: [],
|
|
2489
|
+
columns: [],
|
|
2490
|
+
rows: [],
|
|
2491
|
+
images: [],
|
|
2492
|
+
printSettings: readPrintSettings(fallbackEmptyWorksheet(), sheetIndex, definedNamesBySheet)
|
|
2493
|
+
};
|
|
2494
|
+
return {
|
|
2495
|
+
name: entry.name,
|
|
2496
|
+
cells: readCells(worksheet, sharedStrings),
|
|
2497
|
+
columns: readColumns(worksheet),
|
|
2498
|
+
rows: readRows(worksheet),
|
|
2499
|
+
images: [],
|
|
2500
|
+
printSettings: readPrintSettings(worksheet, sheetIndex, definedNamesBySheet)
|
|
2501
|
+
};
|
|
2502
|
+
}
|
|
2503
|
+
function fallbackEmptyWorksheet() {
|
|
2504
|
+
return {
|
|
2505
|
+
type: "element",
|
|
2506
|
+
tag: "worksheet",
|
|
2507
|
+
attributes: [],
|
|
2508
|
+
children: []
|
|
2509
|
+
};
|
|
2510
|
+
}
|
|
2511
|
+
function readXlsxContent(pkg) {
|
|
2512
|
+
const sharedStrings = loadSharedStrings(pkg);
|
|
2513
|
+
const definedNamesBySheet = readDefinedNamesBySheet(pkg);
|
|
2514
|
+
const sheets = resolveSheetEntries(pkg).map((entry, sheetIndex) => readSheet(pkg, entry, sheetIndex, sharedStrings, definedNamesBySheet));
|
|
2515
|
+
return {
|
|
2516
|
+
kind: "spreadsheet",
|
|
2517
|
+
formatVersion: document_content_model.CONTENT_FORMAT_VERSION,
|
|
2518
|
+
metadata: readCoreProperties(pkg),
|
|
2519
|
+
sheets
|
|
2520
|
+
};
|
|
2521
|
+
}
|
|
2522
|
+
//#endregion
|
|
2523
|
+
//#region src/typed/xlsx/build.ts
|
|
2524
|
+
const SML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
|
|
2525
|
+
const REL_NS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
|
|
2526
|
+
const PKG_RELS_NS = "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
2527
|
+
const CONTENT_TYPES_NS = "http://schemas.openxmlformats.org/package/2006/content-types";
|
|
2528
|
+
const CORE_PROPS_NS = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
|
|
2529
|
+
const DC_NS = "http://purl.org/dc/elements/1.1/";
|
|
2530
|
+
const DCTERMS_NS = "http://purl.org/dc/terms/";
|
|
2531
|
+
const XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
|
|
2532
|
+
const EXTENDED_PROPS_NS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";
|
|
2533
|
+
const CT_WORKBOOK = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
|
|
2534
|
+
const CT_STYLES = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml";
|
|
2535
|
+
const CT_SHARED_STRINGS = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml";
|
|
2536
|
+
const CT_WORKSHEET = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
|
|
2537
|
+
const CT_CORE_PROPS = "application/vnd.openxmlformats-package.core-properties+xml";
|
|
2538
|
+
const CT_EXTENDED_PROPS = "application/vnd.openxmlformats-officedocument.extended-properties+xml";
|
|
2539
|
+
const REL_OFFICE_DOCUMENT = `${REL_NS}/officeDocument`;
|
|
2540
|
+
const REL_CORE_PROPS = `${PKG_RELS_NS}/metadata/core-properties`;
|
|
2541
|
+
const REL_EXTENDED_PROPS = `${REL_NS}/extended-properties`;
|
|
2542
|
+
const REL_WORKSHEET = `${REL_NS}/worksheet`;
|
|
2543
|
+
const REL_STYLES = `${REL_NS}/styles`;
|
|
2544
|
+
const REL_SHARED_STRINGS = `${REL_NS}/sharedStrings`;
|
|
2545
|
+
const MAX_COLUMN_INDEX = 16383;
|
|
2546
|
+
const MAX_ROW_INDEX = 1048575;
|
|
2547
|
+
function xmlDeclaration() {
|
|
2548
|
+
return {
|
|
2549
|
+
type: "declaration",
|
|
2550
|
+
attributes: [
|
|
2551
|
+
{
|
|
2552
|
+
name: "version",
|
|
2553
|
+
value: "1.0"
|
|
2554
|
+
},
|
|
2555
|
+
{
|
|
2556
|
+
name: "encoding",
|
|
2557
|
+
value: "UTF-8"
|
|
2558
|
+
},
|
|
2559
|
+
{
|
|
2560
|
+
name: "standalone",
|
|
2561
|
+
value: "yes"
|
|
2562
|
+
}
|
|
2563
|
+
]
|
|
2564
|
+
};
|
|
2565
|
+
}
|
|
2566
|
+
function xmlPart(root) {
|
|
2567
|
+
return {
|
|
2568
|
+
kind: "xml",
|
|
2569
|
+
nodes: [xmlDeclaration(), root]
|
|
2570
|
+
};
|
|
2571
|
+
}
|
|
2572
|
+
function buildContentTypesPart(sheetCount) {
|
|
2573
|
+
const overrides = [
|
|
2574
|
+
el("Override", {
|
|
2575
|
+
PartName: "/xl/workbook.xml",
|
|
2576
|
+
ContentType: CT_WORKBOOK
|
|
2577
|
+
}),
|
|
2578
|
+
el("Override", {
|
|
2579
|
+
PartName: "/xl/styles.xml",
|
|
2580
|
+
ContentType: CT_STYLES
|
|
2581
|
+
}),
|
|
2582
|
+
el("Override", {
|
|
2583
|
+
PartName: "/xl/sharedStrings.xml",
|
|
2584
|
+
ContentType: CT_SHARED_STRINGS
|
|
2585
|
+
})
|
|
2586
|
+
];
|
|
2587
|
+
for (let index = 0; index < sheetCount; index++) overrides.push(el("Override", {
|
|
2588
|
+
PartName: `/xl/worksheets/sheet${index + 1}.xml`,
|
|
2589
|
+
ContentType: CT_WORKSHEET
|
|
2590
|
+
}));
|
|
2591
|
+
overrides.push(el("Override", {
|
|
2592
|
+
PartName: "/docProps/core.xml",
|
|
2593
|
+
ContentType: CT_CORE_PROPS
|
|
2594
|
+
}));
|
|
2595
|
+
overrides.push(el("Override", {
|
|
2596
|
+
PartName: "/docProps/app.xml",
|
|
2597
|
+
ContentType: CT_EXTENDED_PROPS
|
|
2598
|
+
}));
|
|
2599
|
+
return xmlPart(el("Types", { xmlns: CONTENT_TYPES_NS }, [
|
|
2600
|
+
el("Default", {
|
|
2601
|
+
Extension: "rels",
|
|
2602
|
+
ContentType: "application/vnd.openxmlformats-package.relationships+xml"
|
|
2603
|
+
}),
|
|
2604
|
+
el("Default", {
|
|
2605
|
+
Extension: "xml",
|
|
2606
|
+
ContentType: "application/xml"
|
|
2607
|
+
}),
|
|
2608
|
+
...overrides
|
|
2609
|
+
]));
|
|
2610
|
+
}
|
|
2611
|
+
function buildPackageRelsPart() {
|
|
2612
|
+
return xmlPart(el("Relationships", { xmlns: PKG_RELS_NS }, [
|
|
2613
|
+
el("Relationship", {
|
|
2614
|
+
Id: "rId1",
|
|
2615
|
+
Type: REL_OFFICE_DOCUMENT,
|
|
2616
|
+
Target: "xl/workbook.xml"
|
|
2617
|
+
}),
|
|
2618
|
+
el("Relationship", {
|
|
2619
|
+
Id: "rId2",
|
|
2620
|
+
Type: REL_CORE_PROPS,
|
|
2621
|
+
Target: "docProps/core.xml"
|
|
2622
|
+
}),
|
|
2623
|
+
el("Relationship", {
|
|
2624
|
+
Id: "rId3",
|
|
2625
|
+
Type: REL_EXTENDED_PROPS,
|
|
2626
|
+
Target: "docProps/app.xml"
|
|
2627
|
+
})
|
|
2628
|
+
]));
|
|
2629
|
+
}
|
|
2630
|
+
function worksheetRelId(sheetIndex) {
|
|
2631
|
+
return `rId${sheetIndex + 1}`;
|
|
2632
|
+
}
|
|
2633
|
+
function buildWorkbookRelsPart(sheetCount) {
|
|
2634
|
+
const relationships = [];
|
|
2635
|
+
for (let index = 0; index < sheetCount; index++) relationships.push(el("Relationship", {
|
|
2636
|
+
Id: worksheetRelId(index),
|
|
2637
|
+
Type: REL_WORKSHEET,
|
|
2638
|
+
Target: `worksheets/sheet${index + 1}.xml`
|
|
2639
|
+
}));
|
|
2640
|
+
relationships.push(el("Relationship", {
|
|
2641
|
+
Id: `rId${sheetCount + 1}`,
|
|
2642
|
+
Type: REL_STYLES,
|
|
2643
|
+
Target: "styles.xml"
|
|
2644
|
+
}));
|
|
2645
|
+
relationships.push(el("Relationship", {
|
|
2646
|
+
Id: `rId${sheetCount + 2}`,
|
|
2647
|
+
Type: REL_SHARED_STRINGS,
|
|
2648
|
+
Target: "sharedStrings.xml"
|
|
2649
|
+
}));
|
|
2650
|
+
return xmlPart(el("Relationships", { xmlns: PKG_RELS_NS }, relationships));
|
|
2651
|
+
}
|
|
2652
|
+
function buildDefinedNameElements(sheets) {
|
|
2653
|
+
const elements = [];
|
|
2654
|
+
sheets.forEach((sheet, sheetIndex) => {
|
|
2655
|
+
const { printRange, repeatRows, repeatColumns } = sheet.printSettings;
|
|
2656
|
+
if (printRange !== void 0) {
|
|
2657
|
+
const value = buildPrintAreaValue(sheet.name, printRange);
|
|
2658
|
+
elements.push(el("definedName", {
|
|
2659
|
+
name: XLNM_PRINT_AREA,
|
|
2660
|
+
localSheetId: String(sheetIndex)
|
|
2661
|
+
}, [txt(encodeXmlText(value))]));
|
|
2662
|
+
}
|
|
2663
|
+
if (repeatRows !== void 0 || repeatColumns !== void 0) {
|
|
2664
|
+
const value = buildPrintTitlesValue(sheet.name, repeatRows, repeatColumns);
|
|
2665
|
+
if (value !== void 0) elements.push(el("definedName", {
|
|
2666
|
+
name: XLNM_PRINT_TITLES,
|
|
2667
|
+
localSheetId: String(sheetIndex)
|
|
2668
|
+
}, [txt(encodeXmlText(value))]));
|
|
2669
|
+
}
|
|
2670
|
+
});
|
|
2671
|
+
return elements;
|
|
2672
|
+
}
|
|
2673
|
+
function buildWorkbookPart(sheets) {
|
|
2674
|
+
const children = [el("sheets", {}, sheets.map((sheet, index) => el("sheet", {
|
|
2675
|
+
name: encodeXmlText(sheet.name),
|
|
2676
|
+
sheetId: String(index + 1),
|
|
2677
|
+
"r:id": worksheetRelId(index)
|
|
2678
|
+
})))];
|
|
2679
|
+
const definedNameElements = buildDefinedNameElements(sheets);
|
|
2680
|
+
if (definedNameElements.length > 0) children.push(el("definedNames", {}, definedNameElements));
|
|
2681
|
+
return xmlPart(el("workbook", {
|
|
2682
|
+
xmlns: SML_NS,
|
|
2683
|
+
"xmlns:r": REL_NS
|
|
2684
|
+
}, children));
|
|
2685
|
+
}
|
|
2686
|
+
function buildSharedStringsPart(sharedStrings) {
|
|
2687
|
+
const entries = sharedStrings.entries();
|
|
2688
|
+
const siElements = entries.map((value) => el("si", {}, [el("t", { "xml:space": "preserve" }, [txt(encodeXmlText(value))])]));
|
|
2689
|
+
return xmlPart(el("sst", {
|
|
2690
|
+
xmlns: SML_NS,
|
|
2691
|
+
count: String(entries.length),
|
|
2692
|
+
uniqueCount: String(entries.length)
|
|
2693
|
+
}, siElements));
|
|
2694
|
+
}
|
|
2695
|
+
function buildStylesPart() {
|
|
2696
|
+
return xmlPart(el("styleSheet", { xmlns: SML_NS }, [
|
|
2697
|
+
el("fonts", { count: "1" }, [el("font", {}, [el("sz", { val: "11" }), el("name", { val: "Calibri" })])]),
|
|
2698
|
+
el("fills", { count: "2" }, [el("fill", {}, [el("patternFill", { patternType: "none" })]), el("fill", {}, [el("patternFill", { patternType: "gray125" })])]),
|
|
2699
|
+
el("borders", { count: "1" }, [el("border", {}, [
|
|
2700
|
+
el("left"),
|
|
2701
|
+
el("right"),
|
|
2702
|
+
el("top"),
|
|
2703
|
+
el("bottom"),
|
|
2704
|
+
el("diagonal")
|
|
2705
|
+
])]),
|
|
2706
|
+
el("cellStyleXfs", { count: "1" }, [el("xf", {
|
|
2707
|
+
numFmtId: "0",
|
|
2708
|
+
fontId: "0",
|
|
2709
|
+
fillId: "0",
|
|
2710
|
+
borderId: "0"
|
|
2711
|
+
})]),
|
|
2712
|
+
el("cellXfs", { count: "1" }, [el("xf", {
|
|
2713
|
+
numFmtId: "0",
|
|
2714
|
+
fontId: "0",
|
|
2715
|
+
fillId: "0",
|
|
2716
|
+
borderId: "0",
|
|
2717
|
+
xfId: "0"
|
|
2718
|
+
})]),
|
|
2719
|
+
el("cellStyles", { count: "1" }, [el("cellStyle", {
|
|
2720
|
+
name: "Normal",
|
|
2721
|
+
xfId: "0",
|
|
2722
|
+
builtinId: "0"
|
|
2723
|
+
})])
|
|
2724
|
+
]));
|
|
2725
|
+
}
|
|
2726
|
+
function buildCorePropertiesPart(metadata) {
|
|
2727
|
+
const children = [];
|
|
2728
|
+
if (metadata.title !== void 0) children.push(el("dc:title", {}, [txt(encodeXmlText(metadata.title))]));
|
|
2729
|
+
if (metadata.author !== void 0) children.push(el("dc:creator", {}, [txt(encodeXmlText(metadata.author))]));
|
|
2730
|
+
if (metadata.subject !== void 0) children.push(el("dc:subject", {}, [txt(encodeXmlText(metadata.subject))]));
|
|
2731
|
+
if (metadata.keywords !== void 0 && metadata.keywords.length > 0) children.push(el("cp:keywords", {}, [txt(encodeXmlText(metadata.keywords.join(", ")))]));
|
|
2732
|
+
if (metadata.createdIso !== void 0) children.push(el("dcterms:created", { "xsi:type": "dcterms:W3CDTF" }, [txt(encodeXmlText(metadata.createdIso))]));
|
|
2733
|
+
if (metadata.modifiedIso !== void 0) children.push(el("dcterms:modified", { "xsi:type": "dcterms:W3CDTF" }, [txt(encodeXmlText(metadata.modifiedIso))]));
|
|
2734
|
+
return xmlPart(el("cp:coreProperties", {
|
|
2735
|
+
"xmlns:cp": CORE_PROPS_NS,
|
|
2736
|
+
"xmlns:dc": DC_NS,
|
|
2737
|
+
"xmlns:dcterms": DCTERMS_NS,
|
|
2738
|
+
"xmlns:xsi": XSI_NS
|
|
2739
|
+
}, children));
|
|
2740
|
+
}
|
|
2741
|
+
function buildAppPropertiesPart(metadata) {
|
|
2742
|
+
const children = [];
|
|
2743
|
+
if (metadata.creator !== void 0) children.push(el("Application", {}, [txt(encodeXmlText(metadata.creator))]));
|
|
2744
|
+
return xmlPart(el("Properties", { xmlns: EXTENDED_PROPS_NS }, children));
|
|
2745
|
+
}
|
|
2746
|
+
function computeDimension(sheet) {
|
|
2747
|
+
let maxRow = 0;
|
|
2748
|
+
let maxColumn = 0;
|
|
2749
|
+
let hasAny = false;
|
|
2750
|
+
for (const cell of sheet.cells) {
|
|
2751
|
+
hasAny = true;
|
|
2752
|
+
maxRow = Math.max(maxRow, cell.row);
|
|
2753
|
+
maxColumn = Math.max(maxColumn, cell.column);
|
|
2754
|
+
}
|
|
2755
|
+
for (const column of sheet.columns) {
|
|
2756
|
+
hasAny = true;
|
|
2757
|
+
maxColumn = Math.max(maxColumn, column.index);
|
|
2758
|
+
}
|
|
2759
|
+
for (const row of sheet.rows) {
|
|
2760
|
+
hasAny = true;
|
|
2761
|
+
maxRow = Math.max(maxRow, row.index);
|
|
2762
|
+
}
|
|
2763
|
+
return hasAny ? rangeReference({
|
|
2764
|
+
startRow: 0,
|
|
2765
|
+
startColumn: 0,
|
|
2766
|
+
endRow: maxRow,
|
|
2767
|
+
endColumn: maxColumn
|
|
2768
|
+
}) : "A1";
|
|
2769
|
+
}
|
|
2770
|
+
function buildColsElement(columns) {
|
|
2771
|
+
if (columns.length === 0) return;
|
|
2772
|
+
return el("cols", {}, columns.map((column) => {
|
|
2773
|
+
const attrs = {
|
|
2774
|
+
min: String(column.index + 1),
|
|
2775
|
+
max: String(column.index + 1),
|
|
2776
|
+
width: ptToColumnWidthChars(column.widthPt).toFixed(2),
|
|
2777
|
+
customWidth: "true"
|
|
2778
|
+
};
|
|
2779
|
+
if (column.hidden === true) attrs.hidden = "true";
|
|
2780
|
+
return el("col", attrs);
|
|
2781
|
+
}));
|
|
2782
|
+
}
|
|
2783
|
+
function renderCellValue(value, isFormulaResult, sharedStrings) {
|
|
2784
|
+
switch (value.kind) {
|
|
2785
|
+
case "string":
|
|
2786
|
+
if (isFormulaResult) return {
|
|
2787
|
+
type: "str",
|
|
2788
|
+
content: encodeXmlText(value.value)
|
|
2789
|
+
};
|
|
2790
|
+
return {
|
|
2791
|
+
type: "s",
|
|
2792
|
+
content: String(sharedStrings.intern(value.value))
|
|
2793
|
+
};
|
|
2794
|
+
case "number":
|
|
2795
|
+
case "percentage":
|
|
2796
|
+
case "currency": return { content: String(value.value) };
|
|
2797
|
+
case "boolean": return {
|
|
2798
|
+
type: "b",
|
|
2799
|
+
content: value.value ? "1" : "0"
|
|
2800
|
+
};
|
|
2801
|
+
case "date":
|
|
2802
|
+
case "time": return {
|
|
2803
|
+
type: "d",
|
|
2804
|
+
content: encodeXmlText(value.value)
|
|
2805
|
+
};
|
|
2806
|
+
case "error": return {
|
|
2807
|
+
type: "e",
|
|
2808
|
+
content: encodeXmlText(value.value)
|
|
2809
|
+
};
|
|
2810
|
+
case "empty": return;
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
function buildCellElement(cell, sharedStrings) {
|
|
2814
|
+
const attrs = {
|
|
2815
|
+
r: cellReference(cell.row, cell.column),
|
|
2816
|
+
s: "0"
|
|
2817
|
+
};
|
|
2818
|
+
const children = [];
|
|
2819
|
+
if (cell.formula !== void 0) children.push(el("f", {}, [txt(encodeXmlText(cell.formula))]));
|
|
2820
|
+
const rendered = renderCellValue(cell.value, cell.formula !== void 0, sharedStrings);
|
|
2821
|
+
if (rendered !== void 0) {
|
|
2822
|
+
if (rendered.type !== void 0) attrs.t = rendered.type;
|
|
2823
|
+
children.push(el("v", {}, [txt(rendered.content)]));
|
|
2824
|
+
}
|
|
2825
|
+
return el("c", attrs, children);
|
|
2826
|
+
}
|
|
2827
|
+
function buildSheetDataElement(sheet, sharedStrings) {
|
|
2828
|
+
const cellsByRow = /* @__PURE__ */ new Map();
|
|
2829
|
+
for (const cell of sheet.cells) {
|
|
2830
|
+
const existing = cellsByRow.get(cell.row);
|
|
2831
|
+
if (existing === void 0) cellsByRow.set(cell.row, [cell]);
|
|
2832
|
+
else existing.push(cell);
|
|
2833
|
+
}
|
|
2834
|
+
const rowInfoByIndex = /* @__PURE__ */ new Map();
|
|
2835
|
+
for (const row of sheet.rows) rowInfoByIndex.set(row.index, row);
|
|
2836
|
+
return el("sheetData", {}, Array.from(/* @__PURE__ */ new Set([...cellsByRow.keys(), ...rowInfoByIndex.keys()])).sort((a, b) => a - b).map((rowIndex) => {
|
|
2837
|
+
const cells = (cellsByRow.get(rowIndex) ?? []).slice().sort((a, b) => a.column - b.column);
|
|
2838
|
+
const rowInfo = rowInfoByIndex.get(rowIndex);
|
|
2839
|
+
const attrs = { r: String(rowIndex + 1) };
|
|
2840
|
+
if (rowInfo !== void 0) {
|
|
2841
|
+
attrs.ht = String(rowInfo.heightPt);
|
|
2842
|
+
attrs.customHeight = "true";
|
|
2843
|
+
if (rowInfo.hidden === true) attrs.hidden = "true";
|
|
2844
|
+
}
|
|
2845
|
+
return el("row", attrs, cells.map((cell) => buildCellElement(cell, sharedStrings)));
|
|
2846
|
+
}));
|
|
2847
|
+
}
|
|
2848
|
+
function buildMergeCellsElement(cells) {
|
|
2849
|
+
const merges = cells.filter((cell) => (cell.colSpan ?? 1) > 1 || (cell.rowSpan ?? 1) > 1);
|
|
2850
|
+
if (merges.length === 0) return;
|
|
2851
|
+
const mergeCellElements = merges.map((cell) => {
|
|
2852
|
+
const endRow = cell.row + (cell.rowSpan ?? 1) - 1;
|
|
2853
|
+
const endColumn = cell.column + (cell.colSpan ?? 1) - 1;
|
|
2854
|
+
return el("mergeCell", { ref: rangeReference({
|
|
2855
|
+
startRow: cell.row,
|
|
2856
|
+
startColumn: cell.column,
|
|
2857
|
+
endRow,
|
|
2858
|
+
endColumn
|
|
2859
|
+
}) });
|
|
2860
|
+
});
|
|
2861
|
+
return el("mergeCells", { count: String(mergeCellElements.length) }, mergeCellElements);
|
|
2862
|
+
}
|
|
2863
|
+
function buildSheetPrElement(settings) {
|
|
2864
|
+
return el("sheetPr", {}, [el("pageSetUpPr", { fitToPage: writeXmlBool(settings.fitToPages !== void 0) })]);
|
|
2865
|
+
}
|
|
2866
|
+
function buildPrintOptionsElement(settings) {
|
|
2867
|
+
return el("printOptions", {
|
|
2868
|
+
gridLines: writeXmlBool(settings.gridlines),
|
|
2869
|
+
headings: writeXmlBool(settings.headers)
|
|
2870
|
+
});
|
|
2871
|
+
}
|
|
2872
|
+
function ptToInches(pt) {
|
|
2873
|
+
return String(pt / 72);
|
|
2874
|
+
}
|
|
2875
|
+
function buildPageMarginsElement(settings) {
|
|
2876
|
+
const margins = settings.margins;
|
|
2877
|
+
return el("pageMargins", {
|
|
2878
|
+
left: ptToInches(margins.leftPt),
|
|
2879
|
+
right: ptToInches(margins.rightPt),
|
|
2880
|
+
top: ptToInches(margins.topPt),
|
|
2881
|
+
bottom: ptToInches(margins.bottomPt),
|
|
2882
|
+
header: ptToInches(DEFAULT_HEADER_FOOTER_MARGIN_PT),
|
|
2883
|
+
footer: ptToInches(DEFAULT_HEADER_FOOTER_MARGIN_PT)
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2886
|
+
function buildPageSetupElement(settings) {
|
|
2887
|
+
const attrs = {};
|
|
2888
|
+
const paperCode = pageSizeToPaperSizeCode(settings.pageSize);
|
|
2889
|
+
if (paperCode !== void 0) attrs.paperSize = paperCode;
|
|
2890
|
+
else {
|
|
2891
|
+
attrs.paperWidth = ptToUniversalMeasure(settings.pageSize.widthPt);
|
|
2892
|
+
attrs.paperHeight = ptToUniversalMeasure(settings.pageSize.heightPt);
|
|
2893
|
+
}
|
|
2894
|
+
attrs.scale = String(settings.scale ?? 100);
|
|
2895
|
+
attrs.fitToWidth = String(settings.fitToPages?.width ?? 1);
|
|
2896
|
+
attrs.fitToHeight = String(settings.fitToPages?.height ?? 1);
|
|
2897
|
+
attrs.pageOrder = settings.pageOrder;
|
|
2898
|
+
attrs.orientation = settings.pageSize.widthPt > settings.pageSize.heightPt ? "landscape" : "portrait";
|
|
2899
|
+
return el("pageSetup", attrs);
|
|
2900
|
+
}
|
|
2901
|
+
function buildBreaksElements(settings) {
|
|
2902
|
+
const manualBreaks = settings.manualBreaks;
|
|
2903
|
+
if (manualBreaks === void 0) return {};
|
|
2904
|
+
const result = {};
|
|
2905
|
+
if (manualBreaks.rows.length > 0) {
|
|
2906
|
+
const breaks = manualBreaks.rows.map((id) => el("brk", {
|
|
2907
|
+
id: String(id),
|
|
2908
|
+
min: "0",
|
|
2909
|
+
max: String(MAX_COLUMN_INDEX),
|
|
2910
|
+
man: "1"
|
|
2911
|
+
}));
|
|
2912
|
+
result.rowBreaks = el("rowBreaks", {
|
|
2913
|
+
count: String(breaks.length),
|
|
2914
|
+
manualBreakCount: String(breaks.length)
|
|
2915
|
+
}, breaks);
|
|
2916
|
+
}
|
|
2917
|
+
if (manualBreaks.columns.length > 0) {
|
|
2918
|
+
const breaks = manualBreaks.columns.map((id) => el("brk", {
|
|
2919
|
+
id: String(id),
|
|
2920
|
+
min: "0",
|
|
2921
|
+
max: String(MAX_ROW_INDEX),
|
|
2922
|
+
man: "1"
|
|
2923
|
+
}));
|
|
2924
|
+
result.colBreaks = el("colBreaks", {
|
|
2925
|
+
count: String(breaks.length),
|
|
2926
|
+
manualBreakCount: String(breaks.length)
|
|
2927
|
+
}, breaks);
|
|
2928
|
+
}
|
|
2929
|
+
return result;
|
|
2930
|
+
}
|
|
2931
|
+
function buildWorksheetPart(sheet, sharedStrings) {
|
|
2932
|
+
const children = [buildSheetPrElement(sheet.printSettings), el("dimension", { ref: computeDimension(sheet) })];
|
|
2933
|
+
const colsElement = buildColsElement(sheet.columns);
|
|
2934
|
+
if (colsElement !== void 0) children.push(colsElement);
|
|
2935
|
+
children.push(buildSheetDataElement(sheet, sharedStrings));
|
|
2936
|
+
const mergeCellsElement = buildMergeCellsElement(sheet.cells);
|
|
2937
|
+
if (mergeCellsElement !== void 0) children.push(mergeCellsElement);
|
|
2938
|
+
children.push(buildPrintOptionsElement(sheet.printSettings), buildPageMarginsElement(sheet.printSettings), buildPageSetupElement(sheet.printSettings));
|
|
2939
|
+
const { rowBreaks, colBreaks } = buildBreaksElements(sheet.printSettings);
|
|
2940
|
+
if (rowBreaks !== void 0) children.push(rowBreaks);
|
|
2941
|
+
if (colBreaks !== void 0) children.push(colBreaks);
|
|
2942
|
+
return xmlPart(el("worksheet", {
|
|
2943
|
+
xmlns: SML_NS,
|
|
2944
|
+
"xmlns:r": REL_NS
|
|
2945
|
+
}, children));
|
|
2946
|
+
}
|
|
2947
|
+
function buildXlsxPackage(document) {
|
|
2948
|
+
if (document.kind !== "spreadsheet") throw new Error(`buildXlsxPackage: expected a ContentDocument of kind "spreadsheet", got "${document.kind}"`);
|
|
2949
|
+
const sheets = document.sheets;
|
|
2950
|
+
const sharedStrings = new SharedStringTable();
|
|
2951
|
+
const worksheetParts = sheets.map((sheet) => buildWorksheetPart(sheet, sharedStrings));
|
|
2952
|
+
const parts = {
|
|
2953
|
+
"[Content_Types].xml": buildContentTypesPart(sheets.length),
|
|
2954
|
+
"_rels/.rels": buildPackageRelsPart(),
|
|
2955
|
+
"xl/workbook.xml": buildWorkbookPart(sheets),
|
|
2956
|
+
"xl/_rels/workbook.xml.rels": buildWorkbookRelsPart(sheets.length),
|
|
2957
|
+
"xl/styles.xml": buildStylesPart(),
|
|
2958
|
+
"xl/sharedStrings.xml": buildSharedStringsPart(sharedStrings),
|
|
2959
|
+
"docProps/core.xml": buildCorePropertiesPart(document.metadata),
|
|
2960
|
+
"docProps/app.xml": buildAppPropertiesPart(document.metadata)
|
|
2961
|
+
};
|
|
2962
|
+
worksheetParts.forEach((part, index) => {
|
|
2963
|
+
parts[`xl/worksheets/sheet${index + 1}.xml`] = part;
|
|
2964
|
+
});
|
|
2965
|
+
return { parts };
|
|
2966
|
+
}
|
|
2967
|
+
//#endregion
|
|
1933
2968
|
Object.defineProperty(exports, "AlignmentSchema", {
|
|
1934
2969
|
enumerable: true,
|
|
1935
2970
|
get: function() {
|
|
@@ -1950,6 +2985,12 @@ Object.defineProperty(exports, "COLOR_BLACK", {
|
|
|
1950
2985
|
return document_content_model.COLOR_BLACK;
|
|
1951
2986
|
}
|
|
1952
2987
|
});
|
|
2988
|
+
Object.defineProperty(exports, "CONTENT_FORMAT_VERSION", {
|
|
2989
|
+
enumerable: true,
|
|
2990
|
+
get: function() {
|
|
2991
|
+
return document_content_model.CONTENT_FORMAT_VERSION;
|
|
2992
|
+
}
|
|
2993
|
+
});
|
|
1953
2994
|
Object.defineProperty(exports, "ColorSchema", {
|
|
1954
2995
|
enumerable: true,
|
|
1955
2996
|
get: function() {
|
|
@@ -1966,6 +3007,18 @@ Object.defineProperty(exports, "ContentBlockSchema", {
|
|
|
1966
3007
|
return document_content_model.ContentBlockSchema;
|
|
1967
3008
|
}
|
|
1968
3009
|
});
|
|
3010
|
+
Object.defineProperty(exports, "ContentCellValueSchema", {
|
|
3011
|
+
enumerable: true,
|
|
3012
|
+
get: function() {
|
|
3013
|
+
return document_content_model.ContentCellValueSchema;
|
|
3014
|
+
}
|
|
3015
|
+
});
|
|
3016
|
+
Object.defineProperty(exports, "ContentDocumentSchema", {
|
|
3017
|
+
enumerable: true,
|
|
3018
|
+
get: function() {
|
|
3019
|
+
return document_content_model.ContentDocumentSchema;
|
|
3020
|
+
}
|
|
3021
|
+
});
|
|
1969
3022
|
Object.defineProperty(exports, "ContentImageBlockSchema", {
|
|
1970
3023
|
enumerable: true,
|
|
1971
3024
|
get: function() {
|
|
@@ -2008,6 +3061,54 @@ Object.defineProperty(exports, "ContentShapeSchema", {
|
|
|
2008
3061
|
return document_content_model.ContentShapeSchema;
|
|
2009
3062
|
}
|
|
2010
3063
|
});
|
|
3064
|
+
Object.defineProperty(exports, "ContentSheetCellSchema", {
|
|
3065
|
+
enumerable: true,
|
|
3066
|
+
get: function() {
|
|
3067
|
+
return document_content_model.ContentSheetCellSchema;
|
|
3068
|
+
}
|
|
3069
|
+
});
|
|
3070
|
+
Object.defineProperty(exports, "ContentSheetColumnSchema", {
|
|
3071
|
+
enumerable: true,
|
|
3072
|
+
get: function() {
|
|
3073
|
+
return document_content_model.ContentSheetColumnSchema;
|
|
3074
|
+
}
|
|
3075
|
+
});
|
|
3076
|
+
Object.defineProperty(exports, "ContentSheetImageSchema", {
|
|
3077
|
+
enumerable: true,
|
|
3078
|
+
get: function() {
|
|
3079
|
+
return document_content_model.ContentSheetImageSchema;
|
|
3080
|
+
}
|
|
3081
|
+
});
|
|
3082
|
+
Object.defineProperty(exports, "ContentSheetPrintRangeSchema", {
|
|
3083
|
+
enumerable: true,
|
|
3084
|
+
get: function() {
|
|
3085
|
+
return document_content_model.ContentSheetPrintRangeSchema;
|
|
3086
|
+
}
|
|
3087
|
+
});
|
|
3088
|
+
Object.defineProperty(exports, "ContentSheetPrintSettingsSchema", {
|
|
3089
|
+
enumerable: true,
|
|
3090
|
+
get: function() {
|
|
3091
|
+
return document_content_model.ContentSheetPrintSettingsSchema;
|
|
3092
|
+
}
|
|
3093
|
+
});
|
|
3094
|
+
Object.defineProperty(exports, "ContentSheetRepeatRangeSchema", {
|
|
3095
|
+
enumerable: true,
|
|
3096
|
+
get: function() {
|
|
3097
|
+
return document_content_model.ContentSheetRepeatRangeSchema;
|
|
3098
|
+
}
|
|
3099
|
+
});
|
|
3100
|
+
Object.defineProperty(exports, "ContentSheetRowSchema", {
|
|
3101
|
+
enumerable: true,
|
|
3102
|
+
get: function() {
|
|
3103
|
+
return document_content_model.ContentSheetRowSchema;
|
|
3104
|
+
}
|
|
3105
|
+
});
|
|
3106
|
+
Object.defineProperty(exports, "ContentSheetSchema", {
|
|
3107
|
+
enumerable: true,
|
|
3108
|
+
get: function() {
|
|
3109
|
+
return document_content_model.ContentSheetSchema;
|
|
3110
|
+
}
|
|
3111
|
+
});
|
|
2011
3112
|
Object.defineProperty(exports, "ContentSlideSchema", {
|
|
2012
3113
|
enumerable: true,
|
|
2013
3114
|
get: function() {
|
|
@@ -2089,6 +3190,7 @@ exports.XmlTextSchema = XmlTextSchema;
|
|
|
2089
3190
|
exports.applyColorTransforms = applyColorTransforms;
|
|
2090
3191
|
exports.attr = attr;
|
|
2091
3192
|
exports.base64ToBytes = base64ToBytes;
|
|
3193
|
+
exports.buildXlsxPackage = buildXlsxPackage;
|
|
2092
3194
|
exports.buildXml = buildXml;
|
|
2093
3195
|
exports.bytesToBase64 = bytesToBase64;
|
|
2094
3196
|
exports.childrenWithTag = childrenWithTag;
|
|
@@ -2103,9 +3205,11 @@ exports.compactPackageCodec = compactPackageCodec;
|
|
|
2103
3205
|
exports.decodeCompactPackage = decodeCompactPackage;
|
|
2104
3206
|
exports.decodeEntities = decodeEntities;
|
|
2105
3207
|
exports.decodePackage = decodePackage;
|
|
3208
|
+
exports.el = el;
|
|
2106
3209
|
exports.elementsWithTag = elementsWithTag;
|
|
2107
3210
|
exports.encodeCompactPackage = encodeCompactPackage;
|
|
2108
3211
|
exports.encodePackage = encodePackage;
|
|
3212
|
+
exports.encodeXmlText = encodeXmlText;
|
|
2109
3213
|
exports.fromCompact = fromCompact;
|
|
2110
3214
|
exports.isCompactXmlNode = isCompactXmlNode;
|
|
2111
3215
|
Object.defineProperty(exports, "isContentBlock", {
|
|
@@ -2121,6 +3225,7 @@ exports.parseXml = parseXml;
|
|
|
2121
3225
|
exports.readDocx = readDocx;
|
|
2122
3226
|
exports.readPptx = readPptx;
|
|
2123
3227
|
exports.readXlsx = readXlsx;
|
|
3228
|
+
exports.readXlsxContent = readXlsxContent;
|
|
2124
3229
|
exports.resolveRelationships = resolveRelationships;
|
|
2125
3230
|
Object.defineProperty(exports, "rgbHexToColor", {
|
|
2126
3231
|
enumerable: true,
|
|
@@ -2133,6 +3238,7 @@ exports.serializePackage = serializePackage;
|
|
|
2133
3238
|
exports.sniffImageFormat = sniffImageFormat;
|
|
2134
3239
|
exports.textContent = textContent;
|
|
2135
3240
|
exports.toCompact = toCompact;
|
|
3241
|
+
exports.txt = txt;
|
|
2136
3242
|
exports.unzipPackage = unzipPackage;
|
|
2137
3243
|
exports.walk = walk;
|
|
2138
3244
|
exports.xmlCodec = xmlCodec;
|