@cj-tech-master/excelts 1.5.0 → 1.6.1

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.
Files changed (45) hide show
  1. package/dist/browser/excelts.iife.js +1057 -201
  2. package/dist/browser/excelts.iife.js.map +1 -1
  3. package/dist/browser/excelts.iife.min.js +63 -33
  4. package/dist/cjs/doc/column.js +7 -3
  5. package/dist/cjs/doc/pivot-table.js +149 -61
  6. package/dist/cjs/doc/workbook.js +3 -1
  7. package/dist/cjs/doc/worksheet.js +0 -2
  8. package/dist/cjs/stream/xlsx/worksheet-writer.js +1 -1
  9. package/dist/cjs/utils/unzip/zip-parser.js +2 -5
  10. package/dist/cjs/xlsx/xform/book/workbook-xform.js +3 -0
  11. package/dist/cjs/xlsx/xform/core/content-types-xform.js +19 -14
  12. package/dist/cjs/xlsx/xform/pivot-table/cache-field-xform.js +135 -0
  13. package/dist/cjs/xlsx/xform/pivot-table/cache-field.js +7 -4
  14. package/dist/cjs/xlsx/xform/pivot-table/pivot-cache-definition-xform.js +135 -13
  15. package/dist/cjs/xlsx/xform/pivot-table/pivot-cache-records-xform.js +193 -45
  16. package/dist/cjs/xlsx/xform/pivot-table/pivot-table-xform.js +390 -39
  17. package/dist/cjs/xlsx/xform/sheet/cell-xform.js +6 -0
  18. package/dist/cjs/xlsx/xform/sheet/worksheet-xform.js +14 -3
  19. package/dist/cjs/xlsx/xlsx.js +261 -38
  20. package/dist/esm/doc/column.js +7 -3
  21. package/dist/esm/doc/pivot-table.js +150 -62
  22. package/dist/esm/doc/workbook.js +3 -1
  23. package/dist/esm/doc/worksheet.js +0 -2
  24. package/dist/esm/stream/xlsx/worksheet-writer.js +1 -1
  25. package/dist/esm/utils/unzip/zip-parser.js +2 -5
  26. package/dist/esm/xlsx/xform/book/workbook-xform.js +3 -0
  27. package/dist/esm/xlsx/xform/core/content-types-xform.js +19 -14
  28. package/dist/esm/xlsx/xform/pivot-table/cache-field-xform.js +132 -0
  29. package/dist/esm/xlsx/xform/pivot-table/cache-field.js +7 -4
  30. package/dist/esm/xlsx/xform/pivot-table/pivot-cache-definition-xform.js +135 -13
  31. package/dist/esm/xlsx/xform/pivot-table/pivot-cache-records-xform.js +193 -45
  32. package/dist/esm/xlsx/xform/pivot-table/pivot-table-xform.js +390 -39
  33. package/dist/esm/xlsx/xform/sheet/cell-xform.js +6 -0
  34. package/dist/esm/xlsx/xform/sheet/worksheet-xform.js +14 -3
  35. package/dist/esm/xlsx/xlsx.js +261 -38
  36. package/dist/types/doc/column.d.ts +13 -6
  37. package/dist/types/doc/pivot-table.d.ts +135 -9
  38. package/dist/types/doc/workbook.d.ts +2 -0
  39. package/dist/types/index.d.ts +1 -0
  40. package/dist/types/xlsx/xform/pivot-table/cache-field-xform.d.ts +42 -0
  41. package/dist/types/xlsx/xform/pivot-table/pivot-cache-definition-xform.d.ts +45 -6
  42. package/dist/types/xlsx/xform/pivot-table/pivot-cache-records-xform.d.ts +52 -5
  43. package/dist/types/xlsx/xform/pivot-table/pivot-table-xform.d.ts +98 -5
  44. package/dist/types/xlsx/xlsx.d.ts +27 -0
  45. package/package.json +17 -17
@@ -1,19 +1,58 @@
1
1
  import { BaseXform } from "../base-xform.js";
2
+ import { type CacheFieldModel } from "./cache-field-xform.js";
3
+ import type { PivotTableSource } from "../../../doc/pivot-table.js";
4
+ /**
5
+ * Model for parsed pivot cache definition
6
+ */
7
+ interface ParsedCacheDefinitionModel {
8
+ sourceRef?: string;
9
+ sourceSheet?: string;
10
+ cacheFields: CacheFieldModel[];
11
+ recordCount?: number;
12
+ rId?: string;
13
+ refreshOnLoad?: string;
14
+ refreshedBy?: string;
15
+ refreshedDate?: string;
16
+ createdVersion?: string;
17
+ refreshedVersion?: string;
18
+ minRefreshableVersion?: string;
19
+ isLoaded?: boolean;
20
+ }
21
+ /**
22
+ * Model for generating pivot cache definition (with live source)
23
+ */
2
24
  interface CacheDefinitionModel {
3
- sourceSheet: any;
25
+ source: PivotTableSource;
4
26
  cacheFields: any[];
5
27
  }
6
28
  declare class PivotCacheDefinitionXform extends BaseXform {
7
29
  map: {
8
30
  [key: string]: any;
9
31
  };
32
+ model: ParsedCacheDefinitionModel | null;
33
+ private currentCacheField;
34
+ private inCacheFields;
35
+ private inCacheSource;
10
36
  constructor();
11
37
  prepare(_model: any): void;
12
38
  get tag(): string;
13
- render(xmlStream: any, model: CacheDefinitionModel): void;
14
- parseOpen(_node: any): boolean;
15
- parseText(_text: string): void;
16
- parseClose(_name: string): boolean;
39
+ reset(): void;
40
+ /**
41
+ * Render pivot cache definition XML.
42
+ * Supports both newly created models (with PivotTableSource) and loaded models.
43
+ */
44
+ render(xmlStream: any, model: CacheDefinitionModel | ParsedCacheDefinitionModel): void;
45
+ /**
46
+ * Render newly created pivot cache definition
47
+ */
48
+ private renderNew;
49
+ /**
50
+ * Render loaded pivot cache definition (preserving original structure)
51
+ */
52
+ private renderLoaded;
53
+ parseOpen(node: any): boolean;
54
+ parseText(text: string): void;
55
+ parseClose(name: string): boolean;
17
56
  reconcile(_model: any, _options: any): void;
18
57
  static PIVOT_CACHE_DEFINITION_ATTRIBUTES: {
19
58
  xmlns: string;
@@ -23,4 +62,4 @@ declare class PivotCacheDefinitionXform extends BaseXform {
23
62
  "xmlns:xr": string;
24
63
  };
25
64
  }
26
- export { PivotCacheDefinitionXform };
65
+ export { PivotCacheDefinitionXform, type ParsedCacheDefinitionModel };
@@ -1,19 +1,66 @@
1
1
  import { BaseXform } from "../base-xform.js";
2
+ import type { PivotTableSource } from "../../../doc/pivot-table.js";
3
+ /**
4
+ * Model for generating pivot cache records (with live source)
5
+ */
2
6
  interface CacheRecordsModel {
3
- sourceSheet: any;
7
+ source: PivotTableSource;
4
8
  cacheFields: any[];
5
9
  }
10
+ /**
11
+ * Parsed record value - can be:
12
+ * - { type: 'x', value: number } - Shared item index
13
+ * - { type: 'n', value: number } - Numeric value
14
+ * - { type: 's', value: string } - String value
15
+ * - { type: 'b', value: boolean } - Boolean value
16
+ * - { type: 'm' } - Missing/null value
17
+ * - { type: 'd', value: Date } - Date value
18
+ * - { type: 'e', value: string } - Error value
19
+ */
20
+ interface RecordValue {
21
+ type: "x" | "n" | "s" | "b" | "m" | "d" | "e";
22
+ value?: any;
23
+ }
24
+ /**
25
+ * Parsed cache records model
26
+ */
27
+ interface ParsedCacheRecordsModel {
28
+ records: RecordValue[][];
29
+ count: number;
30
+ isLoaded?: boolean;
31
+ }
6
32
  declare class PivotCacheRecordsXform extends BaseXform {
7
33
  map: {
8
34
  [key: string]: any;
9
35
  };
36
+ model: ParsedCacheRecordsModel | null;
37
+ private currentRecord;
10
38
  constructor();
11
39
  prepare(_model: any): void;
12
40
  get tag(): string;
13
- render(xmlStream: any, model: CacheRecordsModel): void;
14
- parseOpen(_node: any): boolean;
41
+ reset(): void;
42
+ /**
43
+ * Render pivot cache records XML.
44
+ * Supports both newly created models (with PivotTableSource) and loaded models.
45
+ */
46
+ render(xmlStream: any, model: CacheRecordsModel | ParsedCacheRecordsModel): void;
47
+ /**
48
+ * Render newly created pivot cache records
49
+ */
50
+ private renderNew;
51
+ /**
52
+ * Render loaded pivot cache records
53
+ */
54
+ private renderLoaded;
55
+ /**
56
+ * Render a single record value to XML
57
+ */
58
+ private renderRecordValue;
59
+ private renderTableNew;
60
+ private renderCellNew;
61
+ parseOpen(node: any): boolean;
15
62
  parseText(_text: string): void;
16
- parseClose(_name: string): boolean;
63
+ parseClose(name: string): boolean;
17
64
  reconcile(_model: any, _options: any): void;
18
65
  static PIVOT_CACHE_RECORDS_ATTRIBUTES: {
19
66
  xmlns: string;
@@ -23,4 +70,4 @@ declare class PivotCacheRecordsXform extends BaseXform {
23
70
  "xmlns:xr": string;
24
71
  };
25
72
  }
26
- export { PivotCacheRecordsXform };
73
+ export { PivotCacheRecordsXform, type ParsedCacheRecordsModel };
@@ -1,23 +1,116 @@
1
1
  import { BaseXform } from "../base-xform.js";
2
+ /**
3
+ * Model for generating pivot table (with live source)
4
+ */
2
5
  interface PivotTableModel {
3
6
  rows: number[];
4
7
  columns: number[];
5
8
  values: number[];
6
- metric: string;
9
+ metric: "sum" | "count";
7
10
  cacheFields: any[];
8
11
  cacheId: number;
12
+ applyWidthHeightFormats: "0" | "1";
13
+ }
14
+ /**
15
+ * Parsed pivot field
16
+ */
17
+ interface ParsedPivotField {
18
+ axis?: "axisRow" | "axisCol" | "axisPage" | "axisValues";
19
+ dataField?: boolean;
20
+ items?: number[];
21
+ compact?: boolean;
22
+ outline?: boolean;
23
+ showAll?: boolean;
24
+ defaultSubtotal?: boolean;
25
+ }
26
+ /**
27
+ * Parsed data field
28
+ */
29
+ interface ParsedDataField {
30
+ name: string;
31
+ fld: number;
32
+ baseField?: number;
33
+ baseItem?: number;
34
+ subtotal?: "sum" | "count" | "average" | "max" | "min" | "product" | "countNums" | "stdDev" | "stdDevP" | "var" | "varP";
35
+ }
36
+ /**
37
+ * Parsed pivot table model (loaded from file)
38
+ */
39
+ interface ParsedPivotTableModel {
40
+ name?: string;
41
+ cacheId: number;
42
+ uid?: string;
43
+ location?: {
44
+ ref: string;
45
+ firstHeaderRow?: number;
46
+ firstDataRow?: number;
47
+ firstDataCol?: number;
48
+ };
49
+ pivotFields: ParsedPivotField[];
50
+ rowFields: number[];
51
+ colFields: number[];
52
+ dataFields: ParsedDataField[];
53
+ applyNumberFormats?: string;
54
+ applyBorderFormats?: string;
55
+ applyFontFormats?: string;
56
+ applyPatternFormats?: string;
57
+ applyAlignmentFormats?: string;
58
+ applyWidthHeightFormats?: string;
59
+ dataCaption?: string;
60
+ styleName?: string;
61
+ updatedVersion?: string;
62
+ minRefreshableVersion?: string;
63
+ createdVersion?: string;
64
+ useAutoFormatting?: boolean;
65
+ itemPrintTitles?: boolean;
66
+ indent?: number;
67
+ compact?: boolean;
68
+ compactData?: boolean;
69
+ multipleFieldFilters?: boolean;
70
+ rowItems?: any[];
71
+ colItems?: any[];
72
+ isLoaded?: boolean;
73
+ extensions?: any[];
9
74
  }
10
75
  declare class PivotTableXform extends BaseXform {
11
76
  map: {
12
77
  [key: string]: any;
13
78
  };
79
+ model: ParsedPivotTableModel | null;
80
+ private inPivotFields;
81
+ private inRowFields;
82
+ private inColFields;
83
+ private inDataFields;
84
+ private inRowItems;
85
+ private inColItems;
86
+ private inLocation;
87
+ private currentPivotField;
88
+ private inItems;
89
+ private inPivotTableStyleInfo;
14
90
  constructor();
15
91
  prepare(_model: any): void;
16
92
  get tag(): string;
17
- render(xmlStream: any, model: PivotTableModel): void;
18
- parseOpen(_node: any): boolean;
93
+ reset(): void;
94
+ /**
95
+ * Render pivot table XML.
96
+ * Supports both newly created models and loaded models.
97
+ */
98
+ render(xmlStream: any, model: PivotTableModel | ParsedPivotTableModel): void;
99
+ /**
100
+ * Render newly created pivot table
101
+ */
102
+ private renderNew;
103
+ /**
104
+ * Render loaded pivot table (preserving original structure)
105
+ */
106
+ private renderLoaded;
107
+ /**
108
+ * Render a loaded pivot field
109
+ */
110
+ private renderPivotFieldLoaded;
111
+ parseOpen(node: any): boolean;
19
112
  parseText(_text: string): void;
20
- parseClose(_name: string): boolean;
113
+ parseClose(name: string): boolean;
21
114
  reconcile(_model: any, _options: any): void;
22
115
  static PIVOT_TABLE_ATTRIBUTES: {
23
116
  xmlns: string;
@@ -26,4 +119,4 @@ declare class PivotTableXform extends BaseXform {
26
119
  "xmlns:xr": string;
27
120
  };
28
121
  }
29
- export { PivotTableXform };
122
+ export { PivotTableXform, type ParsedPivotTableModel };
@@ -6,6 +6,28 @@ declare class XLSX {
6
6
  parseWorkbook(stream: any): Promise<any>;
7
7
  parseSharedStrings(stream: any): Promise<any>;
8
8
  reconcile(model: any, options?: any): void;
9
+ /**
10
+ * Reconcile pivot tables by linking them to worksheets and their cache data.
11
+ * This builds a complete pivot table model ready for writing.
12
+ */
13
+ private _reconcilePivotTables;
14
+ /**
15
+ * Extract table number from pivot table name (e.g., "pivotTable1" -> 1)
16
+ */
17
+ private _extractTableNumber;
18
+ /**
19
+ * Build a mapping from rId to cacheId using pivotCaches from workbook.xml
20
+ * and workbookRels to determine which definition file corresponds to which cacheId
21
+ */
22
+ private _buildCacheIdMap;
23
+ /**
24
+ * Build a mapping from definition name to cacheId
25
+ */
26
+ private _buildDefinitionToCacheIdMap;
27
+ /**
28
+ * Determine the aggregation metric from dataFields
29
+ */
30
+ private _determineMetric;
9
31
  _processWorksheetEntry(stream: any, model: any, sheetNo: number, options: any, path: string): Promise<void>;
10
32
  _processCommentEntry(stream: any, model: any, name: string): Promise<void>;
11
33
  _processTableEntry(stream: any, model: any, name: string): Promise<void>;
@@ -15,6 +37,11 @@ declare class XLSX {
15
37
  _processDrawingRelsEntry(entry: any, model: any, name: string): Promise<void>;
16
38
  _processVmlDrawingEntry(entry: any, model: any, name: string): Promise<void>;
17
39
  _processThemeEntry(stream: any, model: any, name: string): Promise<void>;
40
+ _processPivotTableEntry(stream: any, model: any, name: string): Promise<void>;
41
+ _processPivotTableRelsEntry(stream: any, model: any, name: string): Promise<void>;
42
+ _processPivotCacheDefinitionEntry(stream: any, model: any, name: string): Promise<void>;
43
+ _processPivotCacheDefinitionRelsEntry(stream: any, model: any, name: string): Promise<void>;
44
+ _processPivotCacheRecordsEntry(stream: any, model: any, name: string): Promise<void>;
18
45
  read(stream: any, options?: any): Promise<any>;
19
46
  load(data: any, options?: any): Promise<any>;
20
47
  loadFromFiles(zipData: Record<string, Uint8Array>, options?: any): Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cj-tech-master/excelts",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "TypeScript Excel Workbook Manager - Read and Write xlsx and csv Files.",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -105,39 +105,39 @@
105
105
  "uuid": "^13.0.0"
106
106
  },
107
107
  "devDependencies": {
108
- "@eslint/js": "^9.39.1",
108
+ "@eslint/js": "^9.39.2",
109
109
  "@oxc-node/core": "^0.0.35",
110
- "@types/node": "^25.0.0",
111
- "@typescript-eslint/eslint-plugin": "^8.49.0",
112
- "@typescript-eslint/parser": "^8.49.0",
113
- "@typescript/native-preview": "^7.0.0-dev.20251208.1",
114
- "@vitest/browser": "^4.0.15",
115
- "@vitest/browser-playwright": "^4.0.15",
116
- "@vitest/ui": "^4.0.15",
110
+ "@types/node": "^25.0.3",
111
+ "@typescript-eslint/eslint-plugin": "^8.50.0",
112
+ "@typescript-eslint/parser": "^8.50.0",
113
+ "@typescript/native-preview": "^7.0.0-dev.20251217.1",
114
+ "@vitest/browser": "^4.0.16",
115
+ "@vitest/browser-playwright": "^4.0.16",
116
+ "@vitest/ui": "^4.0.16",
117
117
  "concurrently": "^9.2.1",
118
118
  "cross-env": "^10.1.0",
119
- "eslint": "^9.39.1",
119
+ "eslint": "^9.39.2",
120
120
  "eslint-config-prettier": "^10.1.8",
121
121
  "eslint-import-resolver-typescript": "^4.4.4",
122
122
  "eslint-plugin-import-x": "^4.16.1",
123
- "eslint-plugin-oxlint": "^1.32.0",
123
+ "eslint-plugin-oxlint": "^1.33.0",
124
124
  "eslint-plugin-unused-imports": "^4.3.0",
125
125
  "express": "^5.2.1",
126
- "fast-xml-parser": "^5.3.2",
126
+ "fast-xml-parser": "^5.3.3",
127
127
  "husky": "^9.1.7",
128
128
  "node-stdlib-browser": "^1.3.1",
129
129
  "nodemon": "^3.1.11",
130
- "oxlint": "^1.32.0",
130
+ "oxlint": "^1.33.0",
131
131
  "playwright": "^1.57.0",
132
132
  "prettier": "^3.7.4",
133
133
  "rimraf": "^6.1.2",
134
- "rolldown": "^1.0.0-beta.54",
134
+ "rolldown": "^1.0.0-beta.55",
135
135
  "rollup-plugin-visualizer": "^6.0.5",
136
136
  "tslib": "^2.8.1",
137
137
  "typescript": "^5.9.3",
138
- "typescript-eslint": "^8.49.0",
139
- "vite-tsconfig-paths": "^5.1.4",
140
- "vitest": "^4.0.15"
138
+ "typescript-eslint": "^8.50.0",
139
+ "vite-tsconfig-paths": "^6.0.2",
140
+ "vitest": "^4.0.16"
141
141
  },
142
142
  "scripts": {
143
143
  "local": "nodemon src/local.ts",