@cj-tech-master/excelts 4.2.3-canary.20260115111903.b80904d → 4.2.3-canary.20260122073152.a9bb6b0
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/browser/modules/csv/csv-core.d.ts +0 -9
- package/dist/browser/modules/csv/csv.browser.js +3 -3
- package/dist/browser/modules/excel/utils/passthrough-manager.d.ts +77 -0
- package/dist/browser/modules/excel/utils/passthrough-manager.js +129 -0
- package/dist/browser/modules/excel/workbook.d.ts +8 -0
- package/dist/browser/modules/excel/workbook.js +9 -1
- package/dist/browser/modules/excel/worksheet.d.ts +4 -0
- package/dist/browser/modules/excel/worksheet.js +4 -1
- package/dist/browser/modules/excel/xlsx/xform/core/content-types-xform.js +16 -10
- package/dist/browser/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.d.ts +34 -11
- package/dist/browser/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.js +256 -86
- package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +38 -11
- package/dist/browser/modules/excel/xlsx/xlsx.browser.d.ts +36 -1
- package/dist/browser/modules/excel/xlsx/xlsx.browser.js +213 -131
- package/dist/cjs/modules/csv/csv.browser.js +3 -3
- package/dist/cjs/modules/excel/utils/passthrough-manager.js +133 -0
- package/dist/cjs/modules/excel/workbook.js +9 -1
- package/dist/cjs/modules/excel/worksheet.js +4 -1
- package/dist/cjs/modules/excel/xlsx/xform/core/content-types-xform.js +16 -10
- package/dist/cjs/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.js +256 -86
- package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +38 -11
- package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +213 -131
- package/dist/esm/modules/csv/csv.browser.js +3 -3
- package/dist/esm/modules/excel/utils/passthrough-manager.js +129 -0
- package/dist/esm/modules/excel/workbook.js +9 -1
- package/dist/esm/modules/excel/worksheet.js +4 -1
- package/dist/esm/modules/excel/xlsx/xform/core/content-types-xform.js +16 -10
- package/dist/esm/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.js +256 -86
- package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +38 -11
- package/dist/esm/modules/excel/xlsx/xlsx.browser.js +213 -131
- package/dist/iife/excelts.iife.js +512 -241
- package/dist/iife/excelts.iife.js.map +1 -1
- package/dist/iife/excelts.iife.min.js +24 -51
- package/dist/types/modules/csv/csv-core.d.ts +0 -9
- package/dist/types/modules/excel/utils/passthrough-manager.d.ts +77 -0
- package/dist/types/modules/excel/workbook.d.ts +8 -0
- package/dist/types/modules/excel/worksheet.d.ts +4 -0
- package/dist/types/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.d.ts +34 -11
- package/dist/types/modules/excel/xlsx/xlsx.browser.d.ts +36 -1
- package/package.json +2 -2
|
@@ -37,6 +37,7 @@ const stream_1 = require("../../archive/zip/stream.js");
|
|
|
37
37
|
const zip_parser_1 = require("../../archive/unzip/zip-parser.js");
|
|
38
38
|
const _stream_1 = require("../../stream/index.js");
|
|
39
39
|
const ooxml_paths_1 = require("../utils/ooxml-paths.js");
|
|
40
|
+
const passthrough_manager_1 = require("../utils/passthrough-manager.js");
|
|
40
41
|
class StreamingZipWriterAdapter {
|
|
41
42
|
constructor(options) {
|
|
42
43
|
this.events = new Map();
|
|
@@ -204,6 +205,7 @@ class XLSX {
|
|
|
204
205
|
this.addDrawings(zip, model);
|
|
205
206
|
this.addTables(zip, model);
|
|
206
207
|
this.addPivotTables(zip, model);
|
|
208
|
+
this.addPassthrough(zip, model);
|
|
207
209
|
await Promise.all([this.addThemes(zip, model), this.addStyles(zip, model)]);
|
|
208
210
|
await this.addFeaturePropertyBag(zip, model);
|
|
209
211
|
await this.addMedia(zip, model);
|
|
@@ -303,8 +305,12 @@ class XLSX {
|
|
|
303
305
|
* This is the foundation for TRUE streaming reads on platforms that have a
|
|
304
306
|
* streaming ZIP parser (e.g. Node.js `modules/archive` Parse).
|
|
305
307
|
*/
|
|
306
|
-
|
|
307
|
-
|
|
308
|
+
/**
|
|
309
|
+
* Create an empty model for parsing XLSX files.
|
|
310
|
+
* Shared by loadFromZipEntries and loadFromFiles.
|
|
311
|
+
*/
|
|
312
|
+
createEmptyModel() {
|
|
313
|
+
return {
|
|
308
314
|
worksheets: [],
|
|
309
315
|
worksheetHash: {},
|
|
310
316
|
worksheetRels: [],
|
|
@@ -313,6 +319,8 @@ class XLSX {
|
|
|
313
319
|
mediaIndex: {},
|
|
314
320
|
drawings: {},
|
|
315
321
|
drawingRels: {},
|
|
322
|
+
// Raw drawing XML data for passthrough (when drawing contains chart references)
|
|
323
|
+
rawDrawings: {},
|
|
316
324
|
comments: {},
|
|
317
325
|
tables: {},
|
|
318
326
|
vmlDrawings: {},
|
|
@@ -320,8 +328,104 @@ class XLSX {
|
|
|
320
328
|
pivotTableRels: {},
|
|
321
329
|
pivotCacheDefinitions: {},
|
|
322
330
|
pivotCacheDefinitionRels: {},
|
|
323
|
-
pivotCacheRecords: {}
|
|
331
|
+
pivotCacheRecords: {},
|
|
332
|
+
// Passthrough storage for unknown/unsupported files (charts, etc.)
|
|
333
|
+
passthrough: {}
|
|
324
334
|
};
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Collect all data from a stream into a single Uint8Array.
|
|
338
|
+
* Reusable helper for passthrough and drawing processing.
|
|
339
|
+
*/
|
|
340
|
+
async collectStreamData(stream) {
|
|
341
|
+
const chunks = [];
|
|
342
|
+
await new Promise((resolve, reject) => {
|
|
343
|
+
stream.on("data", (chunk) => {
|
|
344
|
+
if (typeof chunk === "string") {
|
|
345
|
+
chunks.push(new TextEncoder().encode(chunk));
|
|
346
|
+
}
|
|
347
|
+
else if (chunk instanceof Uint8Array) {
|
|
348
|
+
chunks.push(chunk);
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
chunks.push(new Uint8Array(chunk));
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
stream.on("end", () => resolve());
|
|
355
|
+
stream.on("error", reject);
|
|
356
|
+
});
|
|
357
|
+
return (0, _stream_1.concatUint8Arrays)(chunks);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Check if a drawing has chart references in its relationships
|
|
361
|
+
*/
|
|
362
|
+
drawingHasChartReference(drawing) {
|
|
363
|
+
return (drawing.rels && drawing.rels.some((rel) => rel.Target && rel.Target.includes("/charts/")));
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Check if a drawing rels list references charts.
|
|
367
|
+
* Used to decide whether we need to keep raw drawing XML for passthrough.
|
|
368
|
+
*/
|
|
369
|
+
drawingRelsHasChartReference(drawingRels) {
|
|
370
|
+
return (Array.isArray(drawingRels) &&
|
|
371
|
+
drawingRels.some(rel => typeof rel?.Target === "string" && rel.Target.includes("/charts/")));
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Process a known OOXML entry (workbook, styles, shared strings, etc.)
|
|
375
|
+
* Returns true if handled, false if should be passed to _processDefaultEntry
|
|
376
|
+
*/
|
|
377
|
+
async _processKnownEntry(stream, model, entryName, options) {
|
|
378
|
+
const sheetNo = (0, ooxml_paths_1.getWorksheetNoFromWorksheetPath)(entryName);
|
|
379
|
+
if (sheetNo !== undefined) {
|
|
380
|
+
await this._processWorksheetEntry(stream, model, sheetNo, options, entryName);
|
|
381
|
+
return true;
|
|
382
|
+
}
|
|
383
|
+
switch (entryName) {
|
|
384
|
+
case ooxml_paths_1.OOXML_PATHS.rootRels:
|
|
385
|
+
model.globalRels = await this.parseRels(stream);
|
|
386
|
+
return true;
|
|
387
|
+
case ooxml_paths_1.OOXML_PATHS.xlWorkbook: {
|
|
388
|
+
const workbook = await this.parseWorkbook(stream);
|
|
389
|
+
model.sheets = workbook.sheets;
|
|
390
|
+
model.definedNames = workbook.definedNames;
|
|
391
|
+
model.views = workbook.views;
|
|
392
|
+
model.properties = workbook.properties;
|
|
393
|
+
model.calcProperties = workbook.calcProperties;
|
|
394
|
+
model.pivotCaches = workbook.pivotCaches;
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
case ooxml_paths_1.OOXML_PATHS.xlSharedStrings:
|
|
398
|
+
model.sharedStrings = new shared_strings_xform_1.SharedStringsXform();
|
|
399
|
+
await model.sharedStrings.parseStream(stream);
|
|
400
|
+
return true;
|
|
401
|
+
case ooxml_paths_1.OOXML_PATHS.xlWorkbookRels:
|
|
402
|
+
model.workbookRels = await this.parseRels(stream);
|
|
403
|
+
return true;
|
|
404
|
+
case ooxml_paths_1.OOXML_PATHS.docPropsApp: {
|
|
405
|
+
const appXform = new app_xform_1.AppXform();
|
|
406
|
+
const appProperties = await appXform.parseStream(stream);
|
|
407
|
+
if (appProperties) {
|
|
408
|
+
model.company = appProperties.company;
|
|
409
|
+
model.manager = appProperties.manager;
|
|
410
|
+
}
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
case ooxml_paths_1.OOXML_PATHS.docPropsCore: {
|
|
414
|
+
const coreXform = new core_xform_1.CoreXform();
|
|
415
|
+
const coreProperties = await coreXform.parseStream(stream);
|
|
416
|
+
Object.assign(model, coreProperties);
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
case ooxml_paths_1.OOXML_PATHS.xlStyles:
|
|
420
|
+
model.styles = new styles_xform_1.StylesXform();
|
|
421
|
+
await model.styles.parseStream(stream);
|
|
422
|
+
return true;
|
|
423
|
+
default:
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
async loadFromZipEntries(entries, options) {
|
|
428
|
+
const model = this.createEmptyModel();
|
|
325
429
|
for await (const entry of entries) {
|
|
326
430
|
let drained = false;
|
|
327
431
|
const drainEntry = async () => {
|
|
@@ -338,58 +442,12 @@ class XLSX {
|
|
|
338
442
|
const entryName = (0, ooxml_paths_1.normalizeZipPath)(entry.name);
|
|
339
443
|
const stream = entry.stream;
|
|
340
444
|
try {
|
|
341
|
-
const
|
|
342
|
-
if (
|
|
343
|
-
await this.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
case ooxml_paths_1.OOXML_PATHS.rootRels:
|
|
348
|
-
model.globalRels = await this.parseRels(stream);
|
|
349
|
-
break;
|
|
350
|
-
case ooxml_paths_1.OOXML_PATHS.xlWorkbook: {
|
|
351
|
-
const workbook = await this.parseWorkbook(stream);
|
|
352
|
-
model.sheets = workbook.sheets;
|
|
353
|
-
model.definedNames = workbook.definedNames;
|
|
354
|
-
model.views = workbook.views;
|
|
355
|
-
model.properties = workbook.properties;
|
|
356
|
-
model.calcProperties = workbook.calcProperties;
|
|
357
|
-
model.pivotCaches = workbook.pivotCaches;
|
|
358
|
-
break;
|
|
359
|
-
}
|
|
360
|
-
case ooxml_paths_1.OOXML_PATHS.xlSharedStrings:
|
|
361
|
-
model.sharedStrings = new shared_strings_xform_1.SharedStringsXform();
|
|
362
|
-
await model.sharedStrings.parseStream(stream);
|
|
363
|
-
break;
|
|
364
|
-
case ooxml_paths_1.OOXML_PATHS.xlWorkbookRels:
|
|
365
|
-
model.workbookRels = await this.parseRels(stream);
|
|
366
|
-
break;
|
|
367
|
-
case ooxml_paths_1.OOXML_PATHS.docPropsApp: {
|
|
368
|
-
const appXform = new app_xform_1.AppXform();
|
|
369
|
-
const appProperties = await appXform.parseStream(stream);
|
|
370
|
-
if (appProperties) {
|
|
371
|
-
model.company = appProperties.company;
|
|
372
|
-
model.manager = appProperties.manager;
|
|
373
|
-
}
|
|
374
|
-
break;
|
|
375
|
-
}
|
|
376
|
-
case ooxml_paths_1.OOXML_PATHS.docPropsCore: {
|
|
377
|
-
const coreXform = new core_xform_1.CoreXform();
|
|
378
|
-
const coreProperties = await coreXform.parseStream(stream);
|
|
379
|
-
Object.assign(model, coreProperties);
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
case ooxml_paths_1.OOXML_PATHS.xlStyles:
|
|
383
|
-
model.styles = new styles_xform_1.StylesXform();
|
|
384
|
-
await model.styles.parseStream(stream);
|
|
385
|
-
break;
|
|
386
|
-
default: {
|
|
387
|
-
const handled = await this._processDefaultEntry(stream, model, entryName);
|
|
388
|
-
if (!handled) {
|
|
389
|
-
// Important for true streaming parsers: always consume unknown entries
|
|
390
|
-
await drainEntry();
|
|
391
|
-
}
|
|
392
|
-
break;
|
|
445
|
+
const handled = await this._processKnownEntry(stream, model, entryName, options);
|
|
446
|
+
if (!handled) {
|
|
447
|
+
const defaultHandled = await this._processDefaultEntry(stream, model, entryName);
|
|
448
|
+
if (!defaultHandled) {
|
|
449
|
+
// Important for true streaming parsers: always consume unknown entries
|
|
450
|
+
await drainEntry();
|
|
393
451
|
}
|
|
394
452
|
}
|
|
395
453
|
}
|
|
@@ -503,6 +561,15 @@ class XLSX {
|
|
|
503
561
|
drawingXform.reconcile(drawing, drawingOptions);
|
|
504
562
|
}
|
|
505
563
|
});
|
|
564
|
+
// Trim raw drawings for non-chart drawings to avoid bloating the serialized workbook model.
|
|
565
|
+
if (model.rawDrawings && model.drawingRels) {
|
|
566
|
+
for (const name of Object.keys(model.rawDrawings)) {
|
|
567
|
+
const drawingRel = model.drawingRels[name];
|
|
568
|
+
if (drawingRel && !this.drawingRelsHasChartReference(drawingRel)) {
|
|
569
|
+
delete model.rawDrawings[name];
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
506
573
|
// reconcile tables with the default styles
|
|
507
574
|
const tableOptions = {
|
|
508
575
|
styles: model.styles
|
|
@@ -519,6 +586,7 @@ class XLSX {
|
|
|
519
586
|
mediaIndex: model.mediaIndex,
|
|
520
587
|
date1904: model.properties && model.properties.date1904,
|
|
521
588
|
drawings: model.drawings,
|
|
589
|
+
drawingRels: model.drawingRels,
|
|
522
590
|
comments: model.comments,
|
|
523
591
|
tables: model.tables,
|
|
524
592
|
vmlDrawings: model.vmlDrawings,
|
|
@@ -695,9 +763,15 @@ class XLSX {
|
|
|
695
763
|
}
|
|
696
764
|
}
|
|
697
765
|
async _processDrawingEntry(entry, model, name) {
|
|
766
|
+
// Collect raw data first so we can preserve drawings that reference charts.
|
|
767
|
+
const rawData = await this.collectStreamData(entry);
|
|
768
|
+
// Parse the drawing for normal processing (images, etc.)
|
|
698
769
|
const xform = new drawing_xform_1.DrawingXform();
|
|
699
|
-
const
|
|
770
|
+
const xmlString = this.bufferToString(rawData);
|
|
771
|
+
const drawing = await xform.parseStream(this.createTextStream(xmlString));
|
|
700
772
|
model.drawings[name] = drawing;
|
|
773
|
+
// Store raw data; reconcile() may later drop it if charts are not referenced.
|
|
774
|
+
model.rawDrawings[name] = rawData;
|
|
701
775
|
}
|
|
702
776
|
async _processDrawingRelsEntry(entry, model, name) {
|
|
703
777
|
const xform = new relationships_xform_1.RelationshipsXform();
|
|
@@ -772,24 +846,7 @@ class XLSX {
|
|
|
772
846
|
// loadFromFiles - shared logic for loading from pre-extracted ZIP data
|
|
773
847
|
// ===========================================================================
|
|
774
848
|
async loadFromFiles(zipData, options) {
|
|
775
|
-
const model =
|
|
776
|
-
worksheets: [],
|
|
777
|
-
worksheetHash: {},
|
|
778
|
-
worksheetRels: [],
|
|
779
|
-
themes: {},
|
|
780
|
-
media: [],
|
|
781
|
-
mediaIndex: {},
|
|
782
|
-
drawings: {},
|
|
783
|
-
drawingRels: {},
|
|
784
|
-
comments: {},
|
|
785
|
-
tables: {},
|
|
786
|
-
vmlDrawings: {},
|
|
787
|
-
pivotTables: {},
|
|
788
|
-
pivotTableRels: {},
|
|
789
|
-
pivotCacheDefinitions: {},
|
|
790
|
-
pivotCacheDefinitionRels: {},
|
|
791
|
-
pivotCacheRecords: {}
|
|
792
|
-
};
|
|
849
|
+
const model = this.createEmptyModel();
|
|
793
850
|
const entries = Object.keys(zipData).map(name => ({
|
|
794
851
|
name,
|
|
795
852
|
dir: name.endsWith("/"),
|
|
@@ -803,54 +860,10 @@ class XLSX {
|
|
|
803
860
|
const stream = isBinaryEntry
|
|
804
861
|
? this.createBinaryStream(entry.data)
|
|
805
862
|
: this.createTextStream(this.bufferToString(entry.data));
|
|
806
|
-
const
|
|
807
|
-
if (
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
else {
|
|
811
|
-
switch (entryName) {
|
|
812
|
-
case ooxml_paths_1.OOXML_PATHS.rootRels:
|
|
813
|
-
model.globalRels = await this.parseRels(stream);
|
|
814
|
-
break;
|
|
815
|
-
case ooxml_paths_1.OOXML_PATHS.xlWorkbook: {
|
|
816
|
-
const workbook = await this.parseWorkbook(stream);
|
|
817
|
-
model.sheets = workbook.sheets;
|
|
818
|
-
model.definedNames = workbook.definedNames;
|
|
819
|
-
model.views = workbook.views;
|
|
820
|
-
model.properties = workbook.properties;
|
|
821
|
-
model.calcProperties = workbook.calcProperties;
|
|
822
|
-
model.pivotCaches = workbook.pivotCaches;
|
|
823
|
-
break;
|
|
824
|
-
}
|
|
825
|
-
case ooxml_paths_1.OOXML_PATHS.xlSharedStrings:
|
|
826
|
-
model.sharedStrings = new shared_strings_xform_1.SharedStringsXform();
|
|
827
|
-
await model.sharedStrings.parseStream(stream);
|
|
828
|
-
break;
|
|
829
|
-
case ooxml_paths_1.OOXML_PATHS.xlWorkbookRels:
|
|
830
|
-
model.workbookRels = await this.parseRels(stream);
|
|
831
|
-
break;
|
|
832
|
-
case ooxml_paths_1.OOXML_PATHS.docPropsApp: {
|
|
833
|
-
const appXform = new app_xform_1.AppXform();
|
|
834
|
-
const appProperties = await appXform.parseStream(stream);
|
|
835
|
-
if (appProperties) {
|
|
836
|
-
model.company = appProperties.company;
|
|
837
|
-
model.manager = appProperties.manager;
|
|
838
|
-
}
|
|
839
|
-
break;
|
|
840
|
-
}
|
|
841
|
-
case ooxml_paths_1.OOXML_PATHS.docPropsCore: {
|
|
842
|
-
const coreXform = new core_xform_1.CoreXform();
|
|
843
|
-
const coreProperties = await coreXform.parseStream(stream);
|
|
844
|
-
Object.assign(model, coreProperties);
|
|
845
|
-
break;
|
|
846
|
-
}
|
|
847
|
-
case ooxml_paths_1.OOXML_PATHS.xlStyles:
|
|
848
|
-
model.styles = new styles_xform_1.StylesXform();
|
|
849
|
-
await model.styles.parseStream(stream);
|
|
850
|
-
break;
|
|
851
|
-
default:
|
|
852
|
-
await this._processDefaultEntry(stream, model, entryName);
|
|
853
|
-
}
|
|
863
|
+
const handled = await this._processKnownEntry(stream, model, entryName, options);
|
|
864
|
+
if (!handled) {
|
|
865
|
+
// Pass raw entry data for drawings to enable passthrough
|
|
866
|
+
await this._processDefaultEntry(stream, model, entryName, entry.data);
|
|
854
867
|
}
|
|
855
868
|
}
|
|
856
869
|
}
|
|
@@ -860,11 +873,11 @@ class XLSX {
|
|
|
860
873
|
}
|
|
861
874
|
/**
|
|
862
875
|
* Process default entries (drawings, comments, tables, etc.)
|
|
876
|
+
* @param rawData Optional raw entry data for passthrough preservation (used by loadFromFiles)
|
|
863
877
|
*/
|
|
864
|
-
async _processDefaultEntry(stream, model, entryName) {
|
|
865
|
-
const
|
|
866
|
-
if (
|
|
867
|
-
const sheetNo = worksheetRelsSheetNo;
|
|
878
|
+
async _processDefaultEntry(stream, model, entryName, rawData) {
|
|
879
|
+
const sheetNo = (0, ooxml_paths_1.getWorksheetNoFromWorksheetRelsPath)(entryName);
|
|
880
|
+
if (sheetNo !== undefined) {
|
|
868
881
|
await this._processWorksheetRelsEntry(stream, model, sheetNo);
|
|
869
882
|
return true;
|
|
870
883
|
}
|
|
@@ -876,6 +889,10 @@ class XLSX {
|
|
|
876
889
|
const drawingName = (0, ooxml_paths_1.getDrawingNameFromPath)(entryName);
|
|
877
890
|
if (drawingName) {
|
|
878
891
|
await this._processDrawingEntry(stream, model, drawingName);
|
|
892
|
+
// For loadFromFiles path, store raw data for passthrough (drawings with charts)
|
|
893
|
+
if (rawData) {
|
|
894
|
+
model.rawDrawings[drawingName] = rawData;
|
|
895
|
+
}
|
|
879
896
|
return true;
|
|
880
897
|
}
|
|
881
898
|
const drawingRelsName = (0, ooxml_paths_1.getDrawingNameFromRelsPath)(entryName);
|
|
@@ -930,8 +947,27 @@ class XLSX {
|
|
|
930
947
|
await this._processPivotCacheRecordsEntry(stream, model, pivotCacheRecordsName);
|
|
931
948
|
return true;
|
|
932
949
|
}
|
|
950
|
+
// Store passthrough files (charts, etc.) for preservation
|
|
951
|
+
if (passthrough_manager_1.PassthroughManager.isPassthroughPath(entryName)) {
|
|
952
|
+
// If raw data is available (loadFromFiles path), use it directly
|
|
953
|
+
if (rawData) {
|
|
954
|
+
model.passthrough[entryName] = rawData;
|
|
955
|
+
}
|
|
956
|
+
else {
|
|
957
|
+
await this._processPassthroughEntry(stream, model, entryName);
|
|
958
|
+
}
|
|
959
|
+
return true;
|
|
960
|
+
}
|
|
933
961
|
return false;
|
|
934
962
|
}
|
|
963
|
+
/**
|
|
964
|
+
* Store a passthrough file for preservation during read/write cycles.
|
|
965
|
+
* These files are not parsed but stored as raw bytes to be written back unchanged.
|
|
966
|
+
*/
|
|
967
|
+
async _processPassthroughEntry(stream, model, entryName) {
|
|
968
|
+
const data = await this.collectStreamData(stream);
|
|
969
|
+
model.passthrough[entryName] = data;
|
|
970
|
+
}
|
|
935
971
|
// ===========================================================================
|
|
936
972
|
// Write methods - shared by all platforms
|
|
937
973
|
// ===========================================================================
|
|
@@ -1074,14 +1110,46 @@ class XLSX {
|
|
|
1074
1110
|
addDrawings(zip, model) {
|
|
1075
1111
|
const drawingXform = new drawing_xform_1.DrawingXform();
|
|
1076
1112
|
const relsXform = new relationships_xform_1.RelationshipsXform();
|
|
1113
|
+
const rawDrawings = model.rawDrawings || {};
|
|
1077
1114
|
model.worksheets.forEach((worksheet) => {
|
|
1078
1115
|
const { drawing } = worksheet;
|
|
1079
1116
|
if (drawing) {
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1117
|
+
// Check if drawing rels contain chart references using helper
|
|
1118
|
+
const hasChartReference = this.drawingHasChartReference(drawing);
|
|
1119
|
+
if (hasChartReference && rawDrawings[drawing.name]) {
|
|
1120
|
+
// Use raw data for drawings with chart references (passthrough)
|
|
1121
|
+
zip.append(rawDrawings[drawing.name], { name: (0, ooxml_paths_1.drawingPath)(drawing.name) });
|
|
1122
|
+
}
|
|
1123
|
+
else {
|
|
1124
|
+
// Use regenerated XML for normal drawings (images, shapes)
|
|
1125
|
+
// Filter out invalid anchors (null, undefined, or missing content)
|
|
1126
|
+
const filteredAnchors = (drawing.anchors || []).filter((a) => {
|
|
1127
|
+
if (a == null) {
|
|
1128
|
+
return false;
|
|
1129
|
+
}
|
|
1130
|
+
// Form controls have range.br and shape properties
|
|
1131
|
+
if (a.range?.br && a.shape) {
|
|
1132
|
+
return true;
|
|
1133
|
+
}
|
|
1134
|
+
// One-cell anchors need a valid picture
|
|
1135
|
+
if (!a.br && !a.picture) {
|
|
1136
|
+
return false;
|
|
1137
|
+
}
|
|
1138
|
+
// Two-cell anchors need either picture or shape
|
|
1139
|
+
if (a.br && !a.picture && !a.shape) {
|
|
1140
|
+
return false;
|
|
1141
|
+
}
|
|
1142
|
+
return true;
|
|
1143
|
+
});
|
|
1144
|
+
const drawingForWrite = drawing.anchors
|
|
1145
|
+
? { ...drawing, anchors: filteredAnchors }
|
|
1146
|
+
: drawing;
|
|
1147
|
+
drawingXform.prepare(drawingForWrite);
|
|
1148
|
+
const xml = drawingXform.toXml(drawingForWrite);
|
|
1149
|
+
zip.append(xml, { name: (0, ooxml_paths_1.drawingPath)(drawing.name) });
|
|
1150
|
+
}
|
|
1151
|
+
const relsXml = relsXform.toXml(drawing.rels);
|
|
1152
|
+
zip.append(relsXml, { name: (0, ooxml_paths_1.drawingRelsPath)(drawing.name) });
|
|
1085
1153
|
}
|
|
1086
1154
|
});
|
|
1087
1155
|
}
|
|
@@ -1096,6 +1164,15 @@ class XLSX {
|
|
|
1096
1164
|
});
|
|
1097
1165
|
});
|
|
1098
1166
|
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Write passthrough files (charts, etc.) that were preserved during read.
|
|
1169
|
+
* These files are written back unchanged to preserve unsupported features.
|
|
1170
|
+
*/
|
|
1171
|
+
addPassthrough(zip, model) {
|
|
1172
|
+
const passthroughManager = new passthrough_manager_1.PassthroughManager();
|
|
1173
|
+
passthroughManager.fromRecord(model.passthrough || {});
|
|
1174
|
+
passthroughManager.writeToZip(zip);
|
|
1175
|
+
}
|
|
1099
1176
|
addPivotTables(zip, model) {
|
|
1100
1177
|
if (!model.pivotTables.length) {
|
|
1101
1178
|
return;
|
|
@@ -1188,6 +1265,11 @@ class XLSX {
|
|
|
1188
1265
|
});
|
|
1189
1266
|
// ContentTypesXform expects this flag
|
|
1190
1267
|
model.hasCheckboxes = model.styles.hasCheckboxes;
|
|
1268
|
+
// Build passthroughContentTypes for ContentTypesXform using PassthroughManager
|
|
1269
|
+
const passthrough = model.passthrough || {};
|
|
1270
|
+
const passthroughManager = new passthrough_manager_1.PassthroughManager();
|
|
1271
|
+
passthroughManager.fromRecord(passthrough);
|
|
1272
|
+
model.passthroughContentTypes = passthroughManager.getContentTypes();
|
|
1191
1273
|
}
|
|
1192
1274
|
}
|
|
1193
1275
|
exports.XLSX = XLSX;
|
|
@@ -112,7 +112,7 @@ class CSV {
|
|
|
112
112
|
const dateFormats = options?.dateFormats ?? DEFAULT_DATE_FORMATS;
|
|
113
113
|
const map = options?.map ||
|
|
114
114
|
createDefaultValueMapper(dateFormats, {
|
|
115
|
-
decimalSeparator: options?.valueMapperOptions?.decimalSeparator
|
|
115
|
+
decimalSeparator: options?.valueMapperOptions?.decimalSeparator
|
|
116
116
|
});
|
|
117
117
|
const rows = parseCsv(str, options?.parserOptions);
|
|
118
118
|
for (const row of rows) {
|
|
@@ -154,7 +154,7 @@ class CSV {
|
|
|
154
154
|
const dateFormats = options?.dateFormats ?? DEFAULT_DATE_FORMATS;
|
|
155
155
|
const map = options?.map ||
|
|
156
156
|
createDefaultValueMapper(dateFormats, {
|
|
157
|
-
decimalSeparator: options?.valueMapperOptions?.decimalSeparator
|
|
157
|
+
decimalSeparator: options?.valueMapperOptions?.decimalSeparator
|
|
158
158
|
});
|
|
159
159
|
const parser = new CsvParserStream(options?.parserOptions);
|
|
160
160
|
return new Promise((resolve, reject) => {
|
|
@@ -224,7 +224,7 @@ class CSV {
|
|
|
224
224
|
const dateFormats = options?.dateFormats ?? DEFAULT_DATE_FORMATS;
|
|
225
225
|
const map = options?.map ||
|
|
226
226
|
createDefaultValueMapper(dateFormats, {
|
|
227
|
-
decimalSeparator: options?.valueMapperOptions?.decimalSeparator
|
|
227
|
+
decimalSeparator: options?.valueMapperOptions?.decimalSeparator
|
|
228
228
|
});
|
|
229
229
|
const parser = new CsvParserStream(options?.parserOptions);
|
|
230
230
|
parser.on("data", (row) => worksheet.addRow(row.map(map)));
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PassthroughManager - Manages passthrough files for round-trip preservation
|
|
3
|
+
*
|
|
4
|
+
* This module handles files that are not fully parsed by the library but need to be
|
|
5
|
+
* preserved during read/write cycles (e.g., charts, sparklines, slicers).
|
|
6
|
+
*/
|
|
7
|
+
// Pre-compiled regex patterns for content type detection (performance optimization)
|
|
8
|
+
const chartXmlRegex = /^xl\/charts\/chart\d+\.xml$/;
|
|
9
|
+
const chartStyleXmlRegex = /^xl\/charts\/style\d+\.xml$/;
|
|
10
|
+
const chartColorsXmlRegex = /^xl\/charts\/colors\d+\.xml$/;
|
|
11
|
+
/**
|
|
12
|
+
* Content type definitions for passthrough files
|
|
13
|
+
*/
|
|
14
|
+
const PASSTHROUGH_CONTENT_TYPES = new Map([
|
|
15
|
+
[chartXmlRegex, "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"],
|
|
16
|
+
[chartStyleXmlRegex, "application/vnd.ms-office.chartstyle+xml"],
|
|
17
|
+
[chartColorsXmlRegex, "application/vnd.ms-office.chartcolorstyle+xml"]
|
|
18
|
+
]);
|
|
19
|
+
/**
|
|
20
|
+
* Passthrough path prefixes that should be preserved
|
|
21
|
+
*/
|
|
22
|
+
const PASSTHROUGH_PREFIXES = ["xl/charts/"];
|
|
23
|
+
/**
|
|
24
|
+
* PassthroughManager handles storage and retrieval of passthrough files
|
|
25
|
+
* that need to be preserved during Excel read/write cycles.
|
|
26
|
+
*/
|
|
27
|
+
export class PassthroughManager {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.files = new Map();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if a path should be treated as passthrough
|
|
33
|
+
*/
|
|
34
|
+
static isPassthroughPath(path) {
|
|
35
|
+
return PASSTHROUGH_PREFIXES.some(prefix => path.startsWith(prefix));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get the content type for a passthrough file path
|
|
39
|
+
* @returns Content type string or undefined if unknown
|
|
40
|
+
*/
|
|
41
|
+
static getContentType(path) {
|
|
42
|
+
// Chart relationships are handled by Default extension="rels"
|
|
43
|
+
if (path.startsWith("xl/charts/_rels/")) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
for (const [regex, contentType] of PASSTHROUGH_CONTENT_TYPES) {
|
|
47
|
+
if (regex.test(path)) {
|
|
48
|
+
return contentType;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Add a file to passthrough storage
|
|
55
|
+
*/
|
|
56
|
+
add(path, data) {
|
|
57
|
+
this.files.set(path, data);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get a file from passthrough storage
|
|
61
|
+
*/
|
|
62
|
+
get(path) {
|
|
63
|
+
return this.files.get(path);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if a file exists in passthrough storage
|
|
67
|
+
*/
|
|
68
|
+
has(path) {
|
|
69
|
+
return this.files.has(path);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get all stored paths
|
|
73
|
+
*/
|
|
74
|
+
getPaths() {
|
|
75
|
+
return [...this.files.keys()];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get all files as a record (for serialization)
|
|
79
|
+
*/
|
|
80
|
+
toRecord() {
|
|
81
|
+
const record = {};
|
|
82
|
+
for (const [path, data] of this.files) {
|
|
83
|
+
record[path] = data;
|
|
84
|
+
}
|
|
85
|
+
return record;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Load files from a record (for deserialization)
|
|
89
|
+
*/
|
|
90
|
+
fromRecord(record) {
|
|
91
|
+
this.files.clear();
|
|
92
|
+
for (const [path, data] of Object.entries(record)) {
|
|
93
|
+
this.files.set(path, data);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get content types for all stored files that have known types
|
|
98
|
+
*/
|
|
99
|
+
getContentTypes() {
|
|
100
|
+
const contentTypes = [];
|
|
101
|
+
for (const path of this.files.keys()) {
|
|
102
|
+
const contentType = PassthroughManager.getContentType(path);
|
|
103
|
+
if (contentType) {
|
|
104
|
+
contentTypes.push({ partName: path, contentType });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return contentTypes;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Write all passthrough files to a ZIP writer
|
|
111
|
+
*/
|
|
112
|
+
writeToZip(zip) {
|
|
113
|
+
for (const [path, data] of this.files) {
|
|
114
|
+
zip.append(data, { name: path });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Clear all stored files
|
|
119
|
+
*/
|
|
120
|
+
clear() {
|
|
121
|
+
this.files.clear();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get the number of stored files
|
|
125
|
+
*/
|
|
126
|
+
get size() {
|
|
127
|
+
return this.files.size;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -38,6 +38,8 @@ class Workbook {
|
|
|
38
38
|
this.views = [];
|
|
39
39
|
this.media = [];
|
|
40
40
|
this.pivotTables = [];
|
|
41
|
+
this._passthrough = {};
|
|
42
|
+
this._rawDrawings = {};
|
|
41
43
|
this._definedNames = new DefinedNames();
|
|
42
44
|
}
|
|
43
45
|
// ===========================================================================
|
|
@@ -251,7 +253,9 @@ class Workbook {
|
|
|
251
253
|
themes: this._themes,
|
|
252
254
|
media: this.media,
|
|
253
255
|
pivotTables: this.pivotTables,
|
|
254
|
-
calcProperties: this.calcProperties
|
|
256
|
+
calcProperties: this.calcProperties,
|
|
257
|
+
passthrough: this._passthrough,
|
|
258
|
+
rawDrawings: this._rawDrawings
|
|
255
259
|
};
|
|
256
260
|
}
|
|
257
261
|
set model(value) {
|
|
@@ -292,6 +296,10 @@ class Workbook {
|
|
|
292
296
|
// Handle pivot tables - either newly created or loaded from file
|
|
293
297
|
// Loaded pivot tables come from loadedPivotTables after reconciliation
|
|
294
298
|
this.pivotTables = value.pivotTables || value.loadedPivotTables || [];
|
|
299
|
+
// Preserve passthrough files (charts, etc.) for round-trip preservation
|
|
300
|
+
this._passthrough = value.passthrough || {};
|
|
301
|
+
// Preserve raw drawing data for drawings with chart references
|
|
302
|
+
this._rawDrawings = value.rawDrawings || {};
|
|
295
303
|
}
|
|
296
304
|
}
|
|
297
305
|
// ===========================================================================
|
|
@@ -897,7 +897,8 @@ class Worksheet {
|
|
|
897
897
|
tables: Object.values(this.tables).map(table => table.model),
|
|
898
898
|
pivotTables: this.pivotTables,
|
|
899
899
|
conditionalFormattings: this.conditionalFormattings,
|
|
900
|
-
formControls: this.formControls.map(fc => fc.model)
|
|
900
|
+
formControls: this.formControls.map(fc => fc.model),
|
|
901
|
+
drawing: this._drawing
|
|
901
902
|
};
|
|
902
903
|
// =================================================
|
|
903
904
|
// columns
|
|
@@ -965,6 +966,8 @@ class Worksheet {
|
|
|
965
966
|
this.conditionalFormattings = value.conditionalFormattings;
|
|
966
967
|
// Form controls are currently write-only (not parsed from XLSX)
|
|
967
968
|
this.formControls = [];
|
|
969
|
+
// Preserve loaded drawing data (charts, etc.)
|
|
970
|
+
this._drawing = value.drawing;
|
|
968
971
|
}
|
|
969
972
|
}
|
|
970
973
|
export { Worksheet };
|