@cj-tech-master/excelts 2.0.0 → 2.0.1-canary.20251228093548.379d895

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 (59) hide show
  1. package/dist/browser/excelts.esm.js +217 -126
  2. package/dist/browser/excelts.esm.js.map +1 -1
  3. package/dist/browser/excelts.esm.min.js +37 -34
  4. package/dist/browser/excelts.iife.js +217 -126
  5. package/dist/browser/excelts.iife.js.map +1 -1
  6. package/dist/browser/excelts.iife.min.js +37 -34
  7. package/dist/cjs/doc/pivot-table.js +37 -3
  8. package/dist/cjs/doc/worksheet.js +0 -1
  9. package/dist/cjs/stream/xlsx/worksheet-writer.js +0 -1
  10. package/dist/cjs/utils/datetime.js +7 -156
  11. package/dist/cjs/xlsx/xform/book/sheet-xform.js +3 -2
  12. package/dist/cjs/xlsx/xform/book/workbook-properties-xform.js +1 -1
  13. package/dist/cjs/xlsx/xform/core/content-types-xform.js +12 -6
  14. package/dist/cjs/xlsx/xform/pivot-table/cache-field.js +11 -4
  15. package/dist/cjs/xlsx/xform/pivot-table/pivot-cache-definition-xform.js +4 -11
  16. package/dist/cjs/xlsx/xform/pivot-table/pivot-table-xform.js +124 -17
  17. package/dist/cjs/xlsx/xform/sheet/page-setup-xform.js +4 -3
  18. package/dist/cjs/xlsx/xform/sheet/row-xform.js +1 -1
  19. package/dist/cjs/xlsx/xform/sheet/sheet-format-properties-xform.js +6 -3
  20. package/dist/cjs/xlsx/xform/sheet/sheet-view-xform.js +8 -4
  21. package/dist/cjs/xlsx/xform/sheet/worksheet-xform.js +2 -2
  22. package/dist/cjs/xlsx/xform/style/font-xform.js +36 -23
  23. package/dist/cjs/xlsx/xform/table/auto-filter-xform.js +3 -1
  24. package/dist/cjs/xlsx/xform/table/table-column-xform.js +2 -1
  25. package/dist/cjs/xlsx/xform/table/table-xform.js +5 -9
  26. package/dist/esm/doc/pivot-table.js +37 -3
  27. package/dist/esm/doc/worksheet.js +0 -1
  28. package/dist/esm/stream/xlsx/worksheet-writer.js +0 -1
  29. package/dist/esm/utils/datetime.js +7 -153
  30. package/dist/esm/xlsx/xform/book/sheet-xform.js +3 -2
  31. package/dist/esm/xlsx/xform/book/workbook-properties-xform.js +1 -1
  32. package/dist/esm/xlsx/xform/core/content-types-xform.js +12 -6
  33. package/dist/esm/xlsx/xform/pivot-table/cache-field.js +11 -4
  34. package/dist/esm/xlsx/xform/pivot-table/pivot-cache-definition-xform.js +4 -11
  35. package/dist/esm/xlsx/xform/pivot-table/pivot-table-xform.js +124 -17
  36. package/dist/esm/xlsx/xform/sheet/page-setup-xform.js +4 -3
  37. package/dist/esm/xlsx/xform/sheet/row-xform.js +1 -1
  38. package/dist/esm/xlsx/xform/sheet/sheet-format-properties-xform.js +6 -3
  39. package/dist/esm/xlsx/xform/sheet/sheet-view-xform.js +8 -4
  40. package/dist/esm/xlsx/xform/sheet/worksheet-xform.js +2 -2
  41. package/dist/esm/xlsx/xform/style/font-xform.js +36 -23
  42. package/dist/esm/xlsx/xform/table/auto-filter-xform.js +3 -1
  43. package/dist/esm/xlsx/xform/table/table-column-xform.js +2 -1
  44. package/dist/esm/xlsx/xform/table/table-xform.js +5 -9
  45. package/dist/types/csv/csv-core.d.ts +0 -6
  46. package/dist/types/doc/pivot-table.d.ts +5 -1
  47. package/dist/types/stream/xlsx/workbook-reader.d.ts +1 -1
  48. package/dist/types/stream/xlsx/worksheet-reader.d.ts +1 -1
  49. package/dist/types/stream/xlsx/worksheet-writer.d.ts +1 -1
  50. package/dist/types/types.d.ts +1 -1
  51. package/dist/types/utils/datetime.d.ts +0 -29
  52. package/dist/types/xlsx/xform/pivot-table/cache-field.d.ts +5 -1
  53. package/dist/types/xlsx/xform/pivot-table/pivot-cache-definition-xform.d.ts +0 -5
  54. package/dist/types/xlsx/xform/pivot-table/pivot-table-xform.d.ts +0 -3
  55. package/dist/types/xlsx/xform/sheet/sheet-format-properties-xform.d.ts +1 -1
  56. package/dist/types/xlsx/xform/sheet/worksheet-xform.d.ts +1 -1
  57. package/dist/types/xlsx/xform/style/font-xform.d.ts +1 -0
  58. package/dist/types/xlsx/xform/table/table-xform.d.ts +0 -4
  59. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @cj-tech-master/excelts v2.0.0
2
+ * @cj-tech-master/excelts v2.0.1-canary.20251228093548.379d895
3
3
  * TypeScript Excel Workbook Manager - Read and Write xlsx and csv Files.
4
4
  * (c) 2025 cjnoname
5
5
  * Released under the MIT License
@@ -2965,7 +2965,7 @@ var ExcelTS = (function(exports) {
2965
2965
  const endCol = startCol + columnNames.length - 1;
2966
2966
  const shortRange = colCache.encode(startRow, startCol, endRow, endCol);
2967
2967
  return {
2968
- name: tableModel.name,
2968
+ name: table.worksheet.name,
2969
2969
  getRow(rowNumber) {
2970
2970
  if (rowNumber === 1) return { values: headerRow };
2971
2971
  const dataIndex = rowNumber - 2;
@@ -3049,14 +3049,40 @@ var ExcelTS = (function(exports) {
3049
3049
  }
3050
3050
  return toSortedArray(uniqueValues);
3051
3051
  };
3052
+ const getMinMax = (columnIndex) => {
3053
+ const columnValues = source.getColumn(columnIndex).values;
3054
+ let min = Infinity;
3055
+ let max = -Infinity;
3056
+ let hasNumeric = false;
3057
+ for (let i = 2; i < columnValues.length; i++) {
3058
+ const v = columnValues[i];
3059
+ if (typeof v === "number" && !isNaN(v)) {
3060
+ hasNumeric = true;
3061
+ if (v < min) min = v;
3062
+ if (v > max) max = v;
3063
+ }
3064
+ }
3065
+ return hasNumeric ? {
3066
+ minValue: min,
3067
+ maxValue: max
3068
+ } : null;
3069
+ };
3052
3070
  const result = [];
3053
3071
  for (const columnIndex of range(1, names.length)) {
3054
3072
  const name = names[columnIndex];
3055
- const sharedItems = sharedItemsFields.has(name) ? aggregate(columnIndex) : null;
3056
- result.push({
3073
+ if (sharedItemsFields.has(name)) result.push({
3057
3074
  name,
3058
- sharedItems
3075
+ sharedItems: aggregate(columnIndex)
3059
3076
  });
3077
+ else {
3078
+ const minMax = getMinMax(columnIndex);
3079
+ result.push({
3080
+ name,
3081
+ sharedItems: null,
3082
+ minValue: minMax?.minValue,
3083
+ maxValue: minMax?.maxValue
3084
+ });
3085
+ }
3060
3086
  }
3061
3087
  return result;
3062
3088
  }
@@ -3118,7 +3144,6 @@ var ExcelTS = (function(exports) {
3118
3144
  this.colBreaks = [];
3119
3145
  this.properties = Object.assign({}, {
3120
3146
  defaultRowHeight: 15,
3121
- dyDescent: 55,
3122
3147
  outlineLevelCol: 0,
3123
3148
  outlineLevelRow: 0
3124
3149
  }, options.properties);
@@ -7492,116 +7517,136 @@ var ExcelTS = (function(exports) {
7492
7517
  constructor(options) {
7493
7518
  super();
7494
7519
  this.options = options || FontXform.OPTIONS;
7495
- this.map = {
7496
- b: {
7520
+ const fontProperties = [
7521
+ {
7522
+ tag: "b",
7497
7523
  prop: "bold",
7498
7524
  xform: new BooleanXform({
7499
7525
  tag: "b",
7500
7526
  attr: "val"
7501
7527
  })
7502
7528
  },
7503
- i: {
7529
+ {
7530
+ tag: "i",
7504
7531
  prop: "italic",
7505
7532
  xform: new BooleanXform({
7506
7533
  tag: "i",
7507
7534
  attr: "val"
7508
7535
  })
7509
7536
  },
7510
- u: {
7537
+ {
7538
+ tag: "u",
7511
7539
  prop: "underline",
7512
7540
  xform: new UnderlineXform()
7513
7541
  },
7514
- charset: {
7515
- prop: "charset",
7516
- xform: new IntegerXform({
7517
- tag: "charset",
7542
+ {
7543
+ tag: "strike",
7544
+ prop: "strike",
7545
+ xform: new BooleanXform({
7546
+ tag: "strike",
7518
7547
  attr: "val"
7519
7548
  })
7520
7549
  },
7521
- color: {
7522
- prop: "color",
7523
- xform: new ColorXform()
7524
- },
7525
- condense: {
7550
+ {
7551
+ tag: "condense",
7526
7552
  prop: "condense",
7527
7553
  xform: new BooleanXform({
7528
7554
  tag: "condense",
7529
7555
  attr: "val"
7530
7556
  })
7531
7557
  },
7532
- extend: {
7558
+ {
7559
+ tag: "extend",
7533
7560
  prop: "extend",
7534
7561
  xform: new BooleanXform({
7535
7562
  tag: "extend",
7536
7563
  attr: "val"
7537
7564
  })
7538
7565
  },
7539
- family: {
7540
- prop: "family",
7541
- xform: new IntegerXform({
7542
- tag: "family",
7566
+ {
7567
+ tag: "outline",
7568
+ prop: "outline",
7569
+ xform: new BooleanXform({
7570
+ tag: "outline",
7543
7571
  attr: "val"
7544
7572
  })
7545
7573
  },
7546
- outline: {
7547
- prop: "outline",
7574
+ {
7575
+ tag: "shadow",
7576
+ prop: "shadow",
7548
7577
  xform: new BooleanXform({
7549
- tag: "outline",
7578
+ tag: "shadow",
7550
7579
  attr: "val"
7551
7580
  })
7552
7581
  },
7553
- vertAlign: {
7554
- prop: "vertAlign",
7555
- xform: new StringXform({
7556
- tag: "vertAlign",
7582
+ {
7583
+ tag: "sz",
7584
+ prop: "size",
7585
+ xform: new IntegerXform({
7586
+ tag: "sz",
7557
7587
  attr: "val"
7558
7588
  })
7559
7589
  },
7560
- scheme: {
7561
- prop: "scheme",
7590
+ {
7591
+ tag: "color",
7592
+ prop: "color",
7593
+ xform: new ColorXform()
7594
+ },
7595
+ {
7596
+ tag: this.options.fontNameTag,
7597
+ prop: "name",
7562
7598
  xform: new StringXform({
7563
- tag: "scheme",
7599
+ tag: this.options.fontNameTag,
7564
7600
  attr: "val"
7565
7601
  })
7566
7602
  },
7567
- shadow: {
7568
- prop: "shadow",
7569
- xform: new BooleanXform({
7570
- tag: "shadow",
7603
+ {
7604
+ tag: "family",
7605
+ prop: "family",
7606
+ xform: new IntegerXform({
7607
+ tag: "family",
7571
7608
  attr: "val"
7572
7609
  })
7573
7610
  },
7574
- strike: {
7575
- prop: "strike",
7576
- xform: new BooleanXform({
7577
- tag: "strike",
7611
+ {
7612
+ tag: "scheme",
7613
+ prop: "scheme",
7614
+ xform: new StringXform({
7615
+ tag: "scheme",
7578
7616
  attr: "val"
7579
7617
  })
7580
7618
  },
7581
- sz: {
7582
- prop: "size",
7619
+ {
7620
+ tag: "charset",
7621
+ prop: "charset",
7583
7622
  xform: new IntegerXform({
7584
- tag: "sz",
7623
+ tag: "charset",
7624
+ attr: "val"
7625
+ })
7626
+ },
7627
+ {
7628
+ tag: "vertAlign",
7629
+ prop: "vertAlign",
7630
+ xform: new StringXform({
7631
+ tag: "vertAlign",
7585
7632
  attr: "val"
7586
7633
  })
7587
7634
  }
7588
- };
7589
- this.map[this.options.fontNameTag] = {
7590
- prop: "name",
7591
- xform: new StringXform({
7592
- tag: this.options.fontNameTag,
7593
- attr: "val"
7594
- })
7595
- };
7635
+ ];
7636
+ this.map = Object.fromEntries(fontProperties.map((p) => [p.tag, {
7637
+ prop: p.prop,
7638
+ xform: p.xform
7639
+ }]));
7640
+ this.renderOrder = fontProperties.map((p) => p.tag);
7596
7641
  }
7597
7642
  get tag() {
7598
7643
  return this.options.tagName;
7599
7644
  }
7600
7645
  render(xmlStream, model) {
7601
- const { map } = this;
7646
+ const { map, renderOrder } = this;
7602
7647
  xmlStream.openNode(this.options.tagName);
7603
- Object.entries(this.map).forEach(([tag, defn]) => {
7604
- map[tag].xform.render(xmlStream, model[defn.prop]);
7648
+ renderOrder.forEach((tag) => {
7649
+ map[tag].xform.render(xmlStream, model[map[tag].prop]);
7605
7650
  });
7606
7651
  xmlStream.closeNode();
7607
7652
  }
@@ -9680,10 +9725,6 @@ var ExcelTS = (function(exports) {
9680
9725
  PartName: `/xl/pivotCache/pivotCacheRecords${n}.xml`,
9681
9726
  ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml"
9682
9727
  });
9683
- xmlStream.leafNode("Override", {
9684
- PartName: `/xl/pivotTables/pivotTable${n}.xml`,
9685
- ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
9686
- });
9687
9728
  });
9688
9729
  xmlStream.leafNode("Override", {
9689
9730
  PartName: "/xl/theme/theme1.xml",
@@ -9703,13 +9744,20 @@ var ExcelTS = (function(exports) {
9703
9744
  ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
9704
9745
  });
9705
9746
  });
9747
+ if ((model.pivotTables || []).length) (model.pivotTables || []).forEach((pivotTable) => {
9748
+ const n = pivotTable.tableNumber;
9749
+ xmlStream.leafNode("Override", {
9750
+ PartName: `/xl/pivotTables/pivotTable${n}.xml`,
9751
+ ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
9752
+ });
9753
+ });
9706
9754
  if (model.drawings) model.drawings.forEach((drawing) => {
9707
9755
  xmlStream.leafNode("Override", {
9708
9756
  PartName: `/xl/drawings/${drawing.name}.xml`,
9709
9757
  ContentType: "application/vnd.openxmlformats-officedocument.drawing+xml"
9710
9758
  });
9711
9759
  });
9712
- if (model.commentRefs) {
9760
+ if (model.commentRefs && model.commentRefs.length) {
9713
9761
  xmlStream.leafNode("Default", {
9714
9762
  Extension: "vml",
9715
9763
  ContentType: "application/vnd.openxmlformats-officedocument.vmlDrawing"
@@ -9958,9 +10006,9 @@ var ExcelTS = (function(exports) {
9958
10006
  var WorksheetXform = class extends BaseXform {
9959
10007
  render(xmlStream, model) {
9960
10008
  xmlStream.leafNode("sheet", {
9961
- sheetId: model.id,
9962
10009
  name: model.name,
9963
- state: model.state,
10010
+ sheetId: model.id,
10011
+ state: model.state === "visible" ? void 0 : model.state,
9964
10012
  "r:id": model.rId
9965
10013
  });
9966
10014
  }
@@ -10030,7 +10078,6 @@ var ExcelTS = (function(exports) {
10030
10078
  render(xmlStream, model) {
10031
10079
  xmlStream.leafNode("workbookPr", {
10032
10080
  date1904: model.date1904 ? 1 : void 0,
10033
- defaultThemeVersion: 164011,
10034
10081
  filterPrivacy: 1
10035
10082
  });
10036
10083
  }
@@ -10727,7 +10774,6 @@ var ExcelTS = (function(exports) {
10727
10774
  xmlStream.addAttribute("s", model.styleId);
10728
10775
  xmlStream.addAttribute("customFormat", "1");
10729
10776
  }
10730
- xmlStream.addAttribute("x14ac:dyDescent", "0.25");
10731
10777
  if (model.outlineLevel) xmlStream.addAttribute("outlineLevel", model.outlineLevel);
10732
10778
  if (model.collapsed) xmlStream.addAttribute("collapsed", "1");
10733
10779
  const cellXform = this.map.c;
@@ -11260,9 +11306,9 @@ var ExcelTS = (function(exports) {
11260
11306
  if (model) {
11261
11307
  const attributes = {
11262
11308
  defaultRowHeight: model.defaultRowHeight,
11263
- outlineLevelRow: model.outlineLevelRow,
11264
- outlineLevelCol: model.outlineLevelCol,
11265
- "x14ac:dyDescent": model.dyDescent
11309
+ outlineLevelRow: model.outlineLevelRow || void 0,
11310
+ outlineLevelCol: model.outlineLevelCol || void 0,
11311
+ "x14ac:dyDescent": model.dyDescent || void 0
11266
11312
  };
11267
11313
  if (model.defaultColWidth) attributes.defaultColWidth = model.defaultColWidth;
11268
11314
  if (!model.defaultRowHeight || model.defaultRowHeight !== 15) attributes.customHeight = "1";
@@ -11309,12 +11355,14 @@ var ExcelTS = (function(exports) {
11309
11355
  }
11310
11356
  }
11311
11357
  render(xmlStream, model) {
11312
- xmlStream.openNode("sheetView", { workbookViewId: model.workbookViewId || 0 });
11358
+ const initialAttrs = {};
11359
+ if (model.tabSelected) initialAttrs.tabSelected = "1";
11360
+ initialAttrs.workbookViewId = model.workbookViewId || 0;
11361
+ xmlStream.openNode("sheetView", initialAttrs);
11313
11362
  const add = function(name, value, included) {
11314
11363
  if (included) xmlStream.addAttribute(name, value);
11315
11364
  };
11316
11365
  add("rightToLeft", "1", model.rightToLeft === true);
11317
- add("tabSelected", "1", model.tabSelected);
11318
11366
  add("showRuler", "0", model.showRuler === false);
11319
11367
  add("showRowColHeaders", "0", model.showRowColHeaders === false);
11320
11368
  add("showGridLines", "0", model.showGridLines === false);
@@ -11614,9 +11662,9 @@ var ExcelTS = (function(exports) {
11614
11662
  draft: booleanToXml$1(model.draft),
11615
11663
  cellComments: cellCommentsToXml(model.cellComments),
11616
11664
  errors: errorsToXml(model.errors),
11617
- scale: model.scale,
11618
- fitToWidth: model.fitToWidth,
11619
- fitToHeight: model.fitToHeight,
11665
+ scale: model.scale !== 100 ? model.scale : void 0,
11666
+ fitToWidth: model.fitToWidth !== 1 ? model.fitToWidth : void 0,
11667
+ fitToHeight: model.fitToHeight !== 1 ? model.fitToHeight : void 0,
11620
11668
  firstPageNumber: model.firstPageNumber,
11621
11669
  useFirstPageNumber: booleanToXml$1(!!model.firstPageNumber),
11622
11670
  usePrinterDefaults: booleanToXml$1(model.usePrinterDefaults),
@@ -13008,8 +13056,8 @@ var ExcelTS = (function(exports) {
13008
13056
  xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
13009
13057
  "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
13010
13058
  "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
13011
- "mc:Ignorable": "x14ac",
13012
- "xmlns:x14ac": "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"
13059
+ "xmlns:x14ac": "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac",
13060
+ "mc:Ignorable": "x14ac"
13013
13061
  };
13014
13062
  }
13015
13063
  constructor(options) {
@@ -14276,7 +14324,7 @@ var ExcelTS = (function(exports) {
14276
14324
  id: model.id.toString(),
14277
14325
  name: model.name,
14278
14326
  totalsRowLabel: model.totalsRowLabel,
14279
- totalsRowFunction: model.totalsRowFunction,
14327
+ totalsRowFunction: model.totalsRowFunction === "none" ? void 0 : model.totalsRowFunction,
14280
14328
  dxfId: model.dxfId
14281
14329
  });
14282
14330
  }
@@ -14382,8 +14430,7 @@ var ExcelTS = (function(exports) {
14382
14430
  displayName: model.displayName || model.name,
14383
14431
  ref: model.tableRef,
14384
14432
  totalsRowCount: model.totalsRow ? "1" : void 0,
14385
- totalsRowShown: model.totalsRow ? void 0 : "1",
14386
- headerRowCount: model.headerRow ? "1" : "0"
14433
+ headerRowCount: model.headerRow ? void 0 : "0"
14387
14434
  });
14388
14435
  this.map.autoFilter.render(xmlStream, model);
14389
14436
  this.map.tableColumns.render(xmlStream, model.columns);
@@ -14404,7 +14451,7 @@ var ExcelTS = (function(exports) {
14404
14451
  displayName: attributes.displayName || attributes.name,
14405
14452
  tableRef: attributes.ref,
14406
14453
  totalsRow: attributes.totalsRowCount === "1",
14407
- headerRow: attributes.headerRowCount === "1"
14454
+ headerRow: attributes.headerRowCount !== "0"
14408
14455
  };
14409
14456
  break;
14410
14457
  default:
@@ -14444,13 +14491,7 @@ var ExcelTS = (function(exports) {
14444
14491
  });
14445
14492
  }
14446
14493
  static {
14447
- this.TABLE_ATTRIBUTES = {
14448
- xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
14449
- "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
14450
- "mc:Ignorable": "xr xr3",
14451
- "xmlns:xr": "http://schemas.microsoft.com/office/spreadsheetml/2014/revision",
14452
- "xmlns:xr3": "http://schemas.microsoft.com/office/spreadsheetml/2016/revision3"
14453
- };
14494
+ this.TABLE_ATTRIBUTES = { xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main" };
14454
14495
  }
14455
14496
  };
14456
14497
 
@@ -14634,14 +14675,16 @@ var ExcelTS = (function(exports) {
14634
14675
  //#endregion
14635
14676
  //#region src/xlsx/xform/pivot-table/cache-field.ts
14636
14677
  var CacheField = class {
14637
- constructor({ name, sharedItems }) {
14678
+ constructor({ name, sharedItems, minValue, maxValue }) {
14638
14679
  this.name = name;
14639
14680
  this.sharedItems = sharedItems;
14681
+ this.minValue = minValue;
14682
+ this.maxValue = maxValue;
14640
14683
  }
14641
14684
  render() {
14642
14685
  const escapedName = xmlEncode(this.name);
14643
14686
  if (this.sharedItems === null) return `<cacheField name="${escapedName}" numFmtId="0">
14644
- <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1" />
14687
+ <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1"${this.minValue !== void 0 && this.maxValue !== void 0 ? ` minValue="${this.minValue}" maxValue="${this.maxValue}"` : ""} />
14645
14688
  </cacheField>`;
14646
14689
  return `<cacheField name="${escapedName}" numFmtId="0">
14647
14690
  <sharedItems count="${this.sharedItems.length}">
@@ -14790,17 +14833,16 @@ var ExcelTS = (function(exports) {
14790
14833
  */
14791
14834
  renderNew(xmlStream, model) {
14792
14835
  const { source, cacheFields } = model;
14836
+ const recordCount = source.getSheetValues().slice(2).length;
14793
14837
  xmlStream.openXml(XmlStream.StdDocAttributes);
14794
14838
  xmlStream.openNode(this.tag, {
14795
14839
  ...PivotCacheDefinitionXform.PIVOT_CACHE_DEFINITION_ATTRIBUTES,
14796
14840
  "r:id": "rId1",
14797
14841
  refreshOnLoad: "1",
14798
- refreshedBy: "Author",
14799
- refreshedDate: "45125.026046874998",
14800
14842
  createdVersion: "8",
14801
14843
  refreshedVersion: "8",
14802
14844
  minRefreshableVersion: "3",
14803
- recordCount: cacheFields.length + 1
14845
+ recordCount
14804
14846
  });
14805
14847
  xmlStream.openNode("cacheSource", { type: "worksheet" });
14806
14848
  xmlStream.leafNode("worksheetSource", {
@@ -14823,8 +14865,6 @@ var ExcelTS = (function(exports) {
14823
14865
  ...PivotCacheDefinitionXform.PIVOT_CACHE_DEFINITION_ATTRIBUTES,
14824
14866
  "r:id": model.rId || "rId1",
14825
14867
  refreshOnLoad: model.refreshOnLoad || "1",
14826
- refreshedBy: model.refreshedBy || "Author",
14827
- refreshedDate: model.refreshedDate || "45125.026046874998",
14828
14868
  createdVersion: model.createdVersion || "8",
14829
14869
  refreshedVersion: model.refreshedVersion || "8",
14830
14870
  minRefreshableVersion: model.minRefreshableVersion || "3",
@@ -14854,8 +14894,6 @@ var ExcelTS = (function(exports) {
14854
14894
  cacheFields: [],
14855
14895
  rId: attributes["r:id"],
14856
14896
  refreshOnLoad: attributes.refreshOnLoad,
14857
- refreshedBy: attributes.refreshedBy,
14858
- refreshedDate: attributes.refreshedDate,
14859
14897
  createdVersion: attributes.createdVersion,
14860
14898
  refreshedVersion: attributes.refreshedVersion,
14861
14899
  minRefreshableVersion: attributes.minRefreshableVersion,
@@ -14910,10 +14948,7 @@ var ExcelTS = (function(exports) {
14910
14948
  static {
14911
14949
  this.PIVOT_CACHE_DEFINITION_ATTRIBUTES = {
14912
14950
  xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
14913
- "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
14914
- "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
14915
- "mc:Ignorable": "xr",
14916
- "xmlns:xr": "http://schemas.microsoft.com/office/spreadsheetml/2014/revision"
14951
+ "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
14917
14952
  };
14918
14953
  }
14919
14954
  };
@@ -14966,11 +15001,16 @@ var ExcelTS = (function(exports) {
14966
15001
  */
14967
15002
  renderNew(xmlStream, model) {
14968
15003
  const { rows, columns, values, cacheFields, cacheId, applyWidthHeightFormats } = model;
14969
- const uniqueUid = `{${crypto.randomUUID().toUpperCase()}}`;
15004
+ const rowItems = buildRowItems(rows, cacheFields);
15005
+ const colItems = buildColItems(columns, cacheFields, values.length);
15006
+ const rowFieldItemCount = rows.length > 0 ? cacheFields[rows[0]]?.sharedItems?.length || 0 : 0;
15007
+ const colFieldItemCount = columns.length > 0 ? cacheFields[columns[0]]?.sharedItems?.length || 0 : 0;
15008
+ const endRow = 4 + rowFieldItemCount + 1;
15009
+ const endCol = 1 + colFieldItemCount + 1;
15010
+ const locationRef = `A3:${String.fromCharCode(64 + endCol)}${endRow}`;
14970
15011
  xmlStream.openXml(XmlStream.StdDocAttributes);
14971
15012
  xmlStream.openNode(this.tag, {
14972
15013
  ...PivotTableXform.PIVOT_TABLE_ATTRIBUTES,
14973
- "xr:uid": uniqueUid,
14974
15014
  name: "PivotTable2",
14975
15015
  cacheId,
14976
15016
  applyNumberFormats: "0",
@@ -14991,21 +15031,21 @@ var ExcelTS = (function(exports) {
14991
15031
  multipleFieldFilters: "0"
14992
15032
  });
14993
15033
  xmlStream.writeXml(`
14994
- <location ref="A3:E15" firstHeaderRow="1" firstDataRow="2" firstDataCol="1" />
15034
+ <location ref="${locationRef}" firstHeaderRow="1" firstDataRow="2" firstDataCol="1" />
14995
15035
  <pivotFields count="${cacheFields.length}">
14996
15036
  ${renderPivotFields(model)}
14997
15037
  </pivotFields>
14998
15038
  <rowFields count="${rows.length}">
14999
15039
  ${rows.map((rowIndex) => `<field x="${rowIndex}" />`).join("\n ")}
15000
15040
  </rowFields>
15001
- <rowItems count="1">
15002
- <i t="grand"><x /></i>
15041
+ <rowItems count="${rowItems.count}">
15042
+ ${rowItems.xml}
15003
15043
  </rowItems>
15004
15044
  <colFields count="${columns.length === 0 ? 1 : columns.length}">
15005
15045
  ${columns.length === 0 ? "<field x=\"-2\" />" : columns.map((columnIndex) => `<field x="${columnIndex}" />`).join("\n ")}
15006
15046
  </colFields>
15007
- <colItems count="1">
15008
- <i t="grand"><x /></i>
15047
+ <colItems count="${colItems.count}">
15048
+ ${colItems.xml}
15009
15049
  </colItems>
15010
15050
  <dataFields count="${values.length}">
15011
15051
  ${buildDataFields(cacheFields, values, model.metric)}
@@ -15045,11 +15085,9 @@ var ExcelTS = (function(exports) {
15045
15085
  * Render loaded pivot table (preserving original structure)
15046
15086
  */
15047
15087
  renderLoaded(xmlStream, model) {
15048
- const uniqueUid = model.uid || `{${crypto.randomUUID().toUpperCase()}}`;
15049
15088
  xmlStream.openXml(XmlStream.StdDocAttributes);
15050
15089
  xmlStream.openNode(this.tag, {
15051
15090
  ...PivotTableXform.PIVOT_TABLE_ATTRIBUTES,
15052
- "xr:uid": uniqueUid,
15053
15091
  name: model.name || "PivotTable1",
15054
15092
  cacheId: model.cacheId,
15055
15093
  applyNumberFormats: model.applyNumberFormats || "0",
@@ -15298,15 +15336,64 @@ var ExcelTS = (function(exports) {
15298
15336
  }
15299
15337
  reconcile(_model, _options) {}
15300
15338
  static {
15301
- this.PIVOT_TABLE_ATTRIBUTES = {
15302
- xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
15303
- "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
15304
- "mc:Ignorable": "xr",
15305
- "xmlns:xr": "http://schemas.microsoft.com/office/spreadsheetml/2014/revision"
15306
- };
15339
+ this.PIVOT_TABLE_ATTRIBUTES = { xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main" };
15307
15340
  }
15308
15341
  };
15309
15342
  /**
15343
+ * Build rowItems XML - one item for each unique value in row fields, plus grand total.
15344
+ * Each <i> represents a row in the pivot table.
15345
+ * - Regular items: <i><x/></i> for index 0, <i><x v="index"/></i> for index > 0
15346
+ * - Grand total: <i t="grand"><x/></i>
15347
+ * Note: When v=0, the v attribute should be omitted (Excel convention)
15348
+ */
15349
+ function buildRowItems(rows, cacheFields) {
15350
+ if (rows.length === 0) return {
15351
+ count: 1,
15352
+ xml: "<i t=\"grand\"><x /></i>"
15353
+ };
15354
+ const itemCount = (cacheFields[rows[0]]?.sharedItems || []).length;
15355
+ const items = [];
15356
+ for (let i = 0; i < itemCount; i++) if (i === 0) items.push("<i><x /></i>");
15357
+ else items.push(`<i><x v="${i}" /></i>`);
15358
+ items.push("<i t=\"grand\"><x /></i>");
15359
+ return {
15360
+ count: items.length,
15361
+ xml: items.join("\n ")
15362
+ };
15363
+ }
15364
+ /**
15365
+ * Build colItems XML - one item for each unique value in column fields, plus grand total.
15366
+ * When there are multiple data fields (values), each column value may have sub-columns.
15367
+ * Note: When v=0, the v attribute should be omitted (Excel convention)
15368
+ */
15369
+ function buildColItems(columns, cacheFields, valueCount) {
15370
+ if (columns.length === 0) {
15371
+ if (valueCount > 1) {
15372
+ const items$1 = [];
15373
+ for (let i = 0; i < valueCount; i++) if (i === 0) items$1.push("<i><x /></i>");
15374
+ else items$1.push(`<i><x v="${i}" /></i>`);
15375
+ items$1.push("<i t=\"grand\"><x /></i>");
15376
+ return {
15377
+ count: items$1.length,
15378
+ xml: items$1.join("\n ")
15379
+ };
15380
+ }
15381
+ return {
15382
+ count: 1,
15383
+ xml: "<i t=\"grand\"><x /></i>"
15384
+ };
15385
+ }
15386
+ const itemCount = (cacheFields[columns[0]]?.sharedItems || []).length;
15387
+ const items = [];
15388
+ for (let i = 0; i < itemCount; i++) if (i === 0) items.push("<i><x /></i>");
15389
+ else items.push(`<i><x v="${i}" /></i>`);
15390
+ items.push("<i t=\"grand\"><x /></i>");
15391
+ return {
15392
+ count: items.length,
15393
+ xml: items.join("\n ")
15394
+ };
15395
+ }
15396
+ /**
15310
15397
  * Build dataField XML elements for all values in the pivot table.
15311
15398
  * Supports multiple values when columns is empty.
15312
15399
  */
@@ -15329,18 +15416,22 @@ var ExcelTS = (function(exports) {
15329
15416
  }).join("");
15330
15417
  }
15331
15418
  function renderPivotField(fieldType, sharedItems) {
15332
- const defaultAttributes = "compact=\"0\" outline=\"0\" showAll=\"0\" defaultSubtotal=\"0\"";
15333
- if (fieldType === "row" || fieldType === "column") return `
15334
- <pivotField axis="${fieldType === "row" ? "axisRow" : "axisCol"}" ${defaultAttributes}>
15419
+ if (fieldType === "row" || fieldType === "column") {
15420
+ const axis = fieldType === "row" ? "axisRow" : "axisCol";
15421
+ const axisAttributes = "compact=\"0\" outline=\"0\" showAll=\"0\"";
15422
+ const itemsXml = [...sharedItems.map((_item, index) => `<item x="${index}" />`), "<item t=\"default\" />"].join("\n ");
15423
+ return `
15424
+ <pivotField axis="${axis}" ${axisAttributes}>
15335
15425
  <items count="${sharedItems.length + 1}">
15336
- ${sharedItems.map((_item, index) => `<item x="${index}" />`).join("\n ")}
15426
+ ${itemsXml}
15337
15427
  </items>
15338
15428
  </pivotField>
15339
15429
  `;
15430
+ }
15340
15431
  return `
15341
15432
  <pivotField
15342
15433
  ${fieldType === "value" ? "dataField=\"1\"" : ""}
15343
- ${defaultAttributes}
15434
+ compact="0" outline="0" showAll="0" defaultSubtotal="0"
15344
15435
  />
15345
15436
  `;
15346
15437
  }
@@ -16785,13 +16876,6 @@ var ExcelTS = (function(exports) {
16785
16876
  [25, [parseISOOffset]],
16786
16877
  [29, [parseISOMsOffset]]
16787
16878
  ];
16788
- function tzOffset(d) {
16789
- const off = -d.getTimezoneOffset();
16790
- const sign = off >= 0 ? "+" : "-";
16791
- const h = Math.abs(off) / 60 | 0;
16792
- const m = Math.abs(off) % 60;
16793
- return `${sign}${PAD2[h]}:${PAD2[m]}`;
16794
- }
16795
16879
  /**
16796
16880
  * Optimized date parser for batch processing
16797
16881
  *
@@ -16845,6 +16929,13 @@ var ExcelTS = (function(exports) {
16845
16929
  return out;
16846
16930
  }
16847
16931
  };
16932
+ function tzOffset(d) {
16933
+ const off = -d.getTimezoneOffset();
16934
+ const sign = off >= 0 ? "+" : "-";
16935
+ const h = Math.abs(off) / 60 | 0;
16936
+ const m = Math.abs(off) % 60;
16937
+ return `${sign}${PAD2[h]}:${PAD2[m]}`;
16938
+ }
16848
16939
  /**
16849
16940
  * Optimized date formatter for batch processing
16850
16941
  *