@office-open/xlsx 0.13.0 → 0.13.2
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.mjs +70 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -10735,7 +10735,6 @@ function compileWorksheetPart(wsOpts, i, worksheetConfigs, ctx, mapping, wsConte
|
|
|
10735
10735
|
const groupOpts = wsOpts.groups ?? [];
|
|
10736
10736
|
const hlOpts = wsOpts.hyperlinks ?? [];
|
|
10737
10737
|
const sheetName = wsOpts.name ?? `Sheet${i + 1}`;
|
|
10738
|
-
let sheetXml = stringifyWorksheet(wsOpts, wsContext);
|
|
10739
10738
|
const sheetIdx = wsOpts.sheetId ?? i + 1;
|
|
10740
10739
|
const wsRows = wsOpts.rows ?? [];
|
|
10741
10740
|
for (let ri = 0; ri < wsRows.length; ri++) {
|
|
@@ -10766,13 +10765,68 @@ function compileWorksheetPart(wsOpts, i, worksheetConfigs, ctx, mapping, wsConte
|
|
|
10766
10765
|
const hasQueryTables = queryTableOpts.length > 0;
|
|
10767
10766
|
const singleXmlCellOpts = wsOpts.singleXmlCells ?? [];
|
|
10768
10767
|
const bgImg = wsOpts.backgroundImage;
|
|
10768
|
+
const wsPath = `xl/worksheets/sheet${i + 1}.xml`;
|
|
10769
10769
|
let wsRels;
|
|
10770
|
-
|
|
10771
|
-
|
|
10770
|
+
if (hasMedia || hasExternalHyperlinks || hasComments || hasPivots || hasTables || hasQueryTables || singleXmlCellOpts.length > 0 || bgImg) {
|
|
10771
|
+
wsRels = new Relationships();
|
|
10772
|
+
wsRels.reserveSourceRids(wsPath, passthroughRelationships ?? []);
|
|
10773
|
+
}
|
|
10774
|
+
const resolvePassthroughRid = (typeFragment, originalRid) => {
|
|
10775
|
+
if (!wsRels) return originalRid;
|
|
10776
|
+
const rel = (passthroughRelationships ?? []).find((r) => r.source === wsPath && r.rId === originalRid && r.relationshipType.endsWith(typeFragment));
|
|
10777
|
+
if (!rel) return originalRid;
|
|
10778
|
+
const existing = wsRels.idOf(rel.relationshipType, rel.target);
|
|
10779
|
+
if (existing) return existing;
|
|
10780
|
+
if (wsRels.hasId(originalRid)) return `rId${wsRels.add(rel.relationshipType, rel.target)}`;
|
|
10781
|
+
wsRels.addRelationship(originalRid, rel.relationshipType, rel.target);
|
|
10782
|
+
return originalRid;
|
|
10783
|
+
};
|
|
10784
|
+
const resolveEmbeddingRid = (originalRid) => {
|
|
10785
|
+
const rid = resolvePassthroughRid("/oleObject", originalRid);
|
|
10786
|
+
return rid === originalRid ? resolvePassthroughRid("/package", originalRid) : rid;
|
|
10787
|
+
};
|
|
10788
|
+
let xmlOpts = wsOpts;
|
|
10789
|
+
if (wsRels && (passthroughRelationships?.length ?? 0) > 0) {
|
|
10790
|
+
const oleObjects = wsOpts.oleObjects?.map((ole) => ({
|
|
10791
|
+
...ole,
|
|
10792
|
+
rId: ole.rId ? resolveEmbeddingRid(ole.rId) : ole.rId,
|
|
10793
|
+
properties: ole.properties?.iconRid !== void 0 ? {
|
|
10794
|
+
...ole.properties,
|
|
10795
|
+
iconRid: resolvePassthroughRid("/image", ole.properties.iconRid)
|
|
10796
|
+
} : ole.properties
|
|
10797
|
+
}));
|
|
10798
|
+
const controls = wsOpts.controls?.map((c) => ({
|
|
10799
|
+
...c,
|
|
10800
|
+
rId: resolvePassthroughRid("/controls", c.rId),
|
|
10801
|
+
iconRid: c.iconRid !== void 0 ? resolvePassthroughRid("/image", c.iconRid) : c.iconRid
|
|
10802
|
+
}));
|
|
10803
|
+
const pageSetup = wsOpts.pageSetup?.printerSettingsRId ? {
|
|
10804
|
+
...wsOpts.pageSetup,
|
|
10805
|
+
printerSettingsRId: resolvePassthroughRid("/printerSettings", wsOpts.pageSetup.printerSettingsRId)
|
|
10806
|
+
} : wsOpts.pageSetup;
|
|
10807
|
+
const pivotSelection = wsOpts.pivotSelection?.rId ? {
|
|
10808
|
+
...wsOpts.pivotSelection,
|
|
10809
|
+
rId: resolvePassthroughRid("/pivotTable", wsOpts.pivotSelection.rId)
|
|
10810
|
+
} : wsOpts.pivotSelection;
|
|
10811
|
+
const legacyDrawingHF = wsOpts.legacyDrawingHF ? resolvePassthroughRid("/vmlDrawing", wsOpts.legacyDrawingHF) : wsOpts.legacyDrawingHF;
|
|
10812
|
+
const customProperties = wsOpts.customProperties?.map((cp) => ({
|
|
10813
|
+
...cp,
|
|
10814
|
+
rId: resolvePassthroughRid("/customXml", cp.rId)
|
|
10815
|
+
}));
|
|
10816
|
+
xmlOpts = {
|
|
10817
|
+
...wsOpts,
|
|
10818
|
+
...oleObjects ? { oleObjects } : {},
|
|
10819
|
+
...controls ? { controls } : {},
|
|
10820
|
+
...pageSetup !== wsOpts.pageSetup ? { pageSetup } : {},
|
|
10821
|
+
...pivotSelection !== wsOpts.pivotSelection ? { pivotSelection } : {},
|
|
10822
|
+
...legacyDrawingHF !== wsOpts.legacyDrawingHF ? { legacyDrawingHF } : {},
|
|
10823
|
+
...customProperties ? { customProperties } : {}
|
|
10824
|
+
};
|
|
10825
|
+
}
|
|
10826
|
+
let sheetXml = stringifyWorksheet(xmlOpts, wsContext);
|
|
10772
10827
|
if (hasExternalHyperlinks) for (const hl of hlOpts) {
|
|
10773
10828
|
if (hl.url === void 0) continue;
|
|
10774
|
-
|
|
10775
|
-
wsRels.addRelationship(rid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", hl.url, "External");
|
|
10829
|
+
wsRels.add("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", hl.url, "External");
|
|
10776
10830
|
}
|
|
10777
10831
|
if (hasMedia) {
|
|
10778
10832
|
const drawingImages = [];
|
|
@@ -10904,9 +10958,8 @@ function compileWorksheetPart(wsOpts, i, worksheetConfigs, ctx, mapping, wsConte
|
|
|
10904
10958
|
data: XML_DECL + drawingRels.serialize(),
|
|
10905
10959
|
path: `xl/drawings/_rels/drawing${drawingIdx}.xml.rels`
|
|
10906
10960
|
};
|
|
10907
|
-
const drawingRid =
|
|
10961
|
+
const drawingRid = wsRels.add("http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing", `../drawings/drawing${drawingIdx}.xml`);
|
|
10908
10962
|
sheetXml = editSheetTailMarker(sheetXml, "<!--DRAWING-->", `<drawing r:id="rId${drawingRid}"/>`);
|
|
10909
|
-
wsRels.addRelationship(drawingRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing", `../drawings/drawing${drawingIdx}.xml`);
|
|
10910
10963
|
}
|
|
10911
10964
|
if (hasComments) {
|
|
10912
10965
|
const commentsIdx = i + 1;
|
|
@@ -10920,10 +10973,8 @@ function compileWorksheetPart(wsOpts, i, worksheetConfigs, ctx, mapping, wsConte
|
|
|
10920
10973
|
data: XML_DECL + vmlXml,
|
|
10921
10974
|
path: `xl/drawings/vmlDrawing${commentsIdx}.vml`
|
|
10922
10975
|
};
|
|
10923
|
-
|
|
10924
|
-
wsRels.
|
|
10925
|
-
const vmlRid = ++nextRid;
|
|
10926
|
-
wsRels.addRelationship(vmlRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing", `../drawings/vmlDrawing${commentsIdx}.vml`);
|
|
10976
|
+
wsRels.add("http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", `../comments${commentsIdx}.xml`);
|
|
10977
|
+
const vmlRid = wsRels.add("http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing", `../drawings/vmlDrawing${commentsIdx}.vml`);
|
|
10927
10978
|
sheetXml = editSheetTailMarker(sheetXml, "<!--LEGACY_DRAWING-->", `<legacyDrawing r:id="rId${vmlRid}"/>`);
|
|
10928
10979
|
}
|
|
10929
10980
|
if (bgImg) {
|
|
@@ -10937,25 +10988,9 @@ function compileWorksheetPart(wsOpts, i, worksheetConfigs, ctx, mapping, wsConte
|
|
|
10937
10988
|
height: 0
|
|
10938
10989
|
}));
|
|
10939
10990
|
state.globalMediaIdx++;
|
|
10940
|
-
const bgRid =
|
|
10941
|
-
wsRels.addRelationship(bgRid, IMAGE_REL, `../media/${entry.fileName}`);
|
|
10991
|
+
const bgRid = wsRels.add(IMAGE_REL, `../media/${entry.fileName}`);
|
|
10942
10992
|
sheetXml = editSheetTailMarker(sheetXml, "<!--BACKGROUND_PICTURE-->", `<picture r:id="rId${bgRid}"/>`);
|
|
10943
10993
|
}
|
|
10944
|
-
const wsPath = `xl/worksheets/sheet${i + 1}.xml`;
|
|
10945
|
-
const resolvePassthroughRid = (typeFragment, originalRid) => {
|
|
10946
|
-
if (!wsRels) return originalRid;
|
|
10947
|
-
const rel = (passthroughRelationships ?? []).find((r) => r.source === wsPath && r.rId === originalRid && r.relationshipType.endsWith(typeFragment));
|
|
10948
|
-
if (!rel) return originalRid;
|
|
10949
|
-
const existing = wsRels.idOf(rel.relationshipType, rel.target);
|
|
10950
|
-
if (existing) return existing;
|
|
10951
|
-
if (wsRels.hasId(originalRid)) {
|
|
10952
|
-
const n = ++nextRid;
|
|
10953
|
-
wsRels.addRelationship(n, rel.relationshipType, rel.target);
|
|
10954
|
-
return `rId${n}`;
|
|
10955
|
-
}
|
|
10956
|
-
wsRels.addRelationship(originalRid, rel.relationshipType, rel.target);
|
|
10957
|
-
return originalRid;
|
|
10958
|
-
};
|
|
10959
10994
|
if (wsOpts.drawingRid) {
|
|
10960
10995
|
const rid = escapeXml(resolvePassthroughRid("/drawing", wsOpts.drawingRid));
|
|
10961
10996
|
sheetXml = editSheetTailMarker(sheetXml, "<!--DRAWING-->", `<drawing r:id="${rid}"/>`);
|
|
@@ -11031,8 +11066,7 @@ function compileWorksheetPart(wsOpts, i, worksheetConfigs, ctx, mapping, wsConte
|
|
|
11031
11066
|
data: XML_DECL + ptRels.serialize(),
|
|
11032
11067
|
path: `xl/pivotTables/_rels/pivotTable${pivotIdx}.xml.rels`
|
|
11033
11068
|
};
|
|
11034
|
-
|
|
11035
|
-
wsRels.addRelationship(ptRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable", `../pivotTables/pivotTable${pivotIdx}.xml`);
|
|
11069
|
+
wsRels.add("http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable", `../pivotTables/pivotTable${pivotIdx}.xml`);
|
|
11036
11070
|
}
|
|
11037
11071
|
const wsTableParts = [];
|
|
11038
11072
|
if (hasTables) for (const tbl of tableOpts) {
|
|
@@ -11047,8 +11081,7 @@ function compileWorksheetPart(wsOpts, i, worksheetConfigs, ctx, mapping, wsConte
|
|
|
11047
11081
|
data: tableXmlStr,
|
|
11048
11082
|
path: `xl/tables/table${tableIdx}.xml`
|
|
11049
11083
|
};
|
|
11050
|
-
const tblRid =
|
|
11051
|
-
wsRels.addRelationship(tblRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table", `../tables/table${tableIdx}.xml`);
|
|
11084
|
+
const tblRid = wsRels.add("http://schemas.openxmlformats.org/officeDocument/2006/relationships/table", `../tables/table${tableIdx}.xml`);
|
|
11052
11085
|
wsTableParts.push({ rId: `rId${tblRid}` });
|
|
11053
11086
|
state.allTableParts.push({ rId: `rId${tblRid}` });
|
|
11054
11087
|
}
|
|
@@ -11058,8 +11091,7 @@ function compileWorksheetPart(wsOpts, i, worksheetConfigs, ctx, mapping, wsConte
|
|
|
11058
11091
|
data: XML_DECL + queryTableDesc.stringify(qt, ctx),
|
|
11059
11092
|
path: `xl/queryTables/queryTable${state.globalQueryTableIdx}.xml`
|
|
11060
11093
|
};
|
|
11061
|
-
|
|
11062
|
-
wsRels.addRelationship(qtRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/queryTable", `../queryTables/queryTable${state.globalQueryTableIdx}.xml`);
|
|
11094
|
+
wsRels.add("http://schemas.openxmlformats.org/officeDocument/2006/relationships/queryTable", `../queryTables/queryTable${state.globalQueryTableIdx}.xml`);
|
|
11063
11095
|
}
|
|
11064
11096
|
if (singleXmlCellOpts.length > 0) {
|
|
11065
11097
|
state.globalSingleXmlCellsIdx++;
|
|
@@ -11067,8 +11099,7 @@ function compileWorksheetPart(wsOpts, i, worksheetConfigs, ctx, mapping, wsConte
|
|
|
11067
11099
|
data: XML_DECL + singleXmlCellsDesc.stringify({ cells: singleXmlCellOpts }, ctx),
|
|
11068
11100
|
path: `xl/tables/tableSingleCells${state.globalSingleXmlCellsIdx}.xml`
|
|
11069
11101
|
};
|
|
11070
|
-
|
|
11071
|
-
wsRels.addRelationship(sxcRid, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableSingleCells", `../tables/tableSingleCells${state.globalSingleXmlCellsIdx}.xml`);
|
|
11102
|
+
wsRels.add("http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableSingleCells", `../tables/tableSingleCells${state.globalSingleXmlCellsIdx}.xml`);
|
|
11072
11103
|
}
|
|
11073
11104
|
if (hasPivots) {
|
|
11074
11105
|
const rendered = renderPivotSheetData(pivotOpts, worksheetConfigs, ctx.sharedStrings, sheetName);
|
|
@@ -11079,23 +11110,9 @@ function compileWorksheetPart(wsOpts, i, worksheetConfigs, ctx, mapping, wsConte
|
|
|
11079
11110
|
}
|
|
11080
11111
|
if (wsTableParts.length > 0) sheetXml = editSheetTailMarker(sheetXml, "<!--TABLE_PARTS-->", buildTablePartsXml(wsTableParts));
|
|
11081
11112
|
sheetXml = stripWorksheetPlaceholders(sheetXml);
|
|
11082
|
-
if (wsRels) {
|
|
11083
|
-
if (
|
|
11084
|
-
|
|
11085
|
-
const rid = resolvePassthroughRid("/printerSettings", src);
|
|
11086
|
-
if (rid !== src) sheetXml = sheetXml.replace(new RegExp(`(<pageSetup[^>]*r:id=")${src.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(")`), `$1${rid}$2`);
|
|
11087
|
-
}
|
|
11088
|
-
if (wsOpts.pivotSelection?.rId) {
|
|
11089
|
-
const src = wsOpts.pivotSelection.rId;
|
|
11090
|
-
const rid = resolvePassthroughRid("/pivotTable", src);
|
|
11091
|
-
if (rid !== src) sheetXml = sheetXml.replace(new RegExp(`(<pivotSelection[^>]*r:id=")${src.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(")`), `$1${rid}$2`);
|
|
11092
|
-
}
|
|
11093
|
-
for (const rel of passthroughRelationships ?? []) {
|
|
11094
|
-
if (rel.source !== wsPath) continue;
|
|
11095
|
-
if (wsRels.hasRelationship(rel.relationshipType, rel.target)) continue;
|
|
11096
|
-
const n = ++nextRid;
|
|
11097
|
-
wsRels.addRelationship(n, rel.relationshipType, rel.target);
|
|
11098
|
-
}
|
|
11113
|
+
if (wsRels) for (const rel of passthroughRelationships ?? []) {
|
|
11114
|
+
if (rel.source !== wsPath) continue;
|
|
11115
|
+
wsRels.claimSourceRel(rel);
|
|
11099
11116
|
}
|
|
11100
11117
|
if (wsRels) mapping[`WorksheetRels${i}`] = {
|
|
11101
11118
|
data: XML_DECL + wsRels.serialize(),
|