@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
@@ -2962,7 +2962,7 @@ function createTableSourceAdapter(table) {
2962
2962
  const endCol = startCol + columnNames.length - 1;
2963
2963
  const shortRange = colCache.encode(startRow, startCol, endRow, endCol);
2964
2964
  return {
2965
- name: tableModel.name,
2965
+ name: table.worksheet.name,
2966
2966
  getRow(rowNumber) {
2967
2967
  if (rowNumber === 1) return { values: headerRow };
2968
2968
  const dataIndex = rowNumber - 2;
@@ -3046,14 +3046,40 @@ function makeCacheFields(source, fieldNamesWithSharedItems) {
3046
3046
  }
3047
3047
  return toSortedArray(uniqueValues);
3048
3048
  };
3049
+ const getMinMax = (columnIndex) => {
3050
+ const columnValues = source.getColumn(columnIndex).values;
3051
+ let min = Infinity;
3052
+ let max = -Infinity;
3053
+ let hasNumeric = false;
3054
+ for (let i = 2; i < columnValues.length; i++) {
3055
+ const v = columnValues[i];
3056
+ if (typeof v === "number" && !isNaN(v)) {
3057
+ hasNumeric = true;
3058
+ if (v < min) min = v;
3059
+ if (v > max) max = v;
3060
+ }
3061
+ }
3062
+ return hasNumeric ? {
3063
+ minValue: min,
3064
+ maxValue: max
3065
+ } : null;
3066
+ };
3049
3067
  const result = [];
3050
3068
  for (const columnIndex of range(1, names.length)) {
3051
3069
  const name = names[columnIndex];
3052
- const sharedItems = sharedItemsFields.has(name) ? aggregate(columnIndex) : null;
3053
- result.push({
3070
+ if (sharedItemsFields.has(name)) result.push({
3054
3071
  name,
3055
- sharedItems
3072
+ sharedItems: aggregate(columnIndex)
3056
3073
  });
3074
+ else {
3075
+ const minMax = getMinMax(columnIndex);
3076
+ result.push({
3077
+ name,
3078
+ sharedItems: null,
3079
+ minValue: minMax?.minValue,
3080
+ maxValue: minMax?.maxValue
3081
+ });
3082
+ }
3057
3083
  }
3058
3084
  return result;
3059
3085
  }
@@ -3115,7 +3141,6 @@ var Worksheet = class {
3115
3141
  this.colBreaks = [];
3116
3142
  this.properties = Object.assign({}, {
3117
3143
  defaultRowHeight: 15,
3118
- dyDescent: 55,
3119
3144
  outlineLevelCol: 0,
3120
3145
  outlineLevelRow: 0
3121
3146
  }, options.properties);
@@ -7489,116 +7514,136 @@ var FontXform = class FontXform extends BaseXform {
7489
7514
  constructor(options) {
7490
7515
  super();
7491
7516
  this.options = options || FontXform.OPTIONS;
7492
- this.map = {
7493
- b: {
7517
+ const fontProperties = [
7518
+ {
7519
+ tag: "b",
7494
7520
  prop: "bold",
7495
7521
  xform: new BooleanXform({
7496
7522
  tag: "b",
7497
7523
  attr: "val"
7498
7524
  })
7499
7525
  },
7500
- i: {
7526
+ {
7527
+ tag: "i",
7501
7528
  prop: "italic",
7502
7529
  xform: new BooleanXform({
7503
7530
  tag: "i",
7504
7531
  attr: "val"
7505
7532
  })
7506
7533
  },
7507
- u: {
7534
+ {
7535
+ tag: "u",
7508
7536
  prop: "underline",
7509
7537
  xform: new UnderlineXform()
7510
7538
  },
7511
- charset: {
7512
- prop: "charset",
7513
- xform: new IntegerXform({
7514
- tag: "charset",
7539
+ {
7540
+ tag: "strike",
7541
+ prop: "strike",
7542
+ xform: new BooleanXform({
7543
+ tag: "strike",
7515
7544
  attr: "val"
7516
7545
  })
7517
7546
  },
7518
- color: {
7519
- prop: "color",
7520
- xform: new ColorXform()
7521
- },
7522
- condense: {
7547
+ {
7548
+ tag: "condense",
7523
7549
  prop: "condense",
7524
7550
  xform: new BooleanXform({
7525
7551
  tag: "condense",
7526
7552
  attr: "val"
7527
7553
  })
7528
7554
  },
7529
- extend: {
7555
+ {
7556
+ tag: "extend",
7530
7557
  prop: "extend",
7531
7558
  xform: new BooleanXform({
7532
7559
  tag: "extend",
7533
7560
  attr: "val"
7534
7561
  })
7535
7562
  },
7536
- family: {
7537
- prop: "family",
7538
- xform: new IntegerXform({
7539
- tag: "family",
7563
+ {
7564
+ tag: "outline",
7565
+ prop: "outline",
7566
+ xform: new BooleanXform({
7567
+ tag: "outline",
7540
7568
  attr: "val"
7541
7569
  })
7542
7570
  },
7543
- outline: {
7544
- prop: "outline",
7571
+ {
7572
+ tag: "shadow",
7573
+ prop: "shadow",
7545
7574
  xform: new BooleanXform({
7546
- tag: "outline",
7575
+ tag: "shadow",
7547
7576
  attr: "val"
7548
7577
  })
7549
7578
  },
7550
- vertAlign: {
7551
- prop: "vertAlign",
7552
- xform: new StringXform({
7553
- tag: "vertAlign",
7579
+ {
7580
+ tag: "sz",
7581
+ prop: "size",
7582
+ xform: new IntegerXform({
7583
+ tag: "sz",
7554
7584
  attr: "val"
7555
7585
  })
7556
7586
  },
7557
- scheme: {
7558
- prop: "scheme",
7587
+ {
7588
+ tag: "color",
7589
+ prop: "color",
7590
+ xform: new ColorXform()
7591
+ },
7592
+ {
7593
+ tag: this.options.fontNameTag,
7594
+ prop: "name",
7559
7595
  xform: new StringXform({
7560
- tag: "scheme",
7596
+ tag: this.options.fontNameTag,
7561
7597
  attr: "val"
7562
7598
  })
7563
7599
  },
7564
- shadow: {
7565
- prop: "shadow",
7566
- xform: new BooleanXform({
7567
- tag: "shadow",
7600
+ {
7601
+ tag: "family",
7602
+ prop: "family",
7603
+ xform: new IntegerXform({
7604
+ tag: "family",
7568
7605
  attr: "val"
7569
7606
  })
7570
7607
  },
7571
- strike: {
7572
- prop: "strike",
7573
- xform: new BooleanXform({
7574
- tag: "strike",
7608
+ {
7609
+ tag: "scheme",
7610
+ prop: "scheme",
7611
+ xform: new StringXform({
7612
+ tag: "scheme",
7575
7613
  attr: "val"
7576
7614
  })
7577
7615
  },
7578
- sz: {
7579
- prop: "size",
7616
+ {
7617
+ tag: "charset",
7618
+ prop: "charset",
7580
7619
  xform: new IntegerXform({
7581
- tag: "sz",
7620
+ tag: "charset",
7621
+ attr: "val"
7622
+ })
7623
+ },
7624
+ {
7625
+ tag: "vertAlign",
7626
+ prop: "vertAlign",
7627
+ xform: new StringXform({
7628
+ tag: "vertAlign",
7582
7629
  attr: "val"
7583
7630
  })
7584
7631
  }
7585
- };
7586
- this.map[this.options.fontNameTag] = {
7587
- prop: "name",
7588
- xform: new StringXform({
7589
- tag: this.options.fontNameTag,
7590
- attr: "val"
7591
- })
7592
- };
7632
+ ];
7633
+ this.map = Object.fromEntries(fontProperties.map((p) => [p.tag, {
7634
+ prop: p.prop,
7635
+ xform: p.xform
7636
+ }]));
7637
+ this.renderOrder = fontProperties.map((p) => p.tag);
7593
7638
  }
7594
7639
  get tag() {
7595
7640
  return this.options.tagName;
7596
7641
  }
7597
7642
  render(xmlStream, model) {
7598
- const { map } = this;
7643
+ const { map, renderOrder } = this;
7599
7644
  xmlStream.openNode(this.options.tagName);
7600
- Object.entries(this.map).forEach(([tag, defn]) => {
7601
- map[tag].xform.render(xmlStream, model[defn.prop]);
7645
+ renderOrder.forEach((tag) => {
7646
+ map[tag].xform.render(xmlStream, model[map[tag].prop]);
7602
7647
  });
7603
7648
  xmlStream.closeNode();
7604
7649
  }
@@ -9677,10 +9722,6 @@ var ContentTypesXform = class ContentTypesXform extends BaseXform {
9677
9722
  PartName: `/xl/pivotCache/pivotCacheRecords${n}.xml`,
9678
9723
  ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml"
9679
9724
  });
9680
- xmlStream.leafNode("Override", {
9681
- PartName: `/xl/pivotTables/pivotTable${n}.xml`,
9682
- ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
9683
- });
9684
9725
  });
9685
9726
  xmlStream.leafNode("Override", {
9686
9727
  PartName: "/xl/theme/theme1.xml",
@@ -9700,13 +9741,20 @@ var ContentTypesXform = class ContentTypesXform extends BaseXform {
9700
9741
  ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
9701
9742
  });
9702
9743
  });
9744
+ if ((model.pivotTables || []).length) (model.pivotTables || []).forEach((pivotTable) => {
9745
+ const n = pivotTable.tableNumber;
9746
+ xmlStream.leafNode("Override", {
9747
+ PartName: `/xl/pivotTables/pivotTable${n}.xml`,
9748
+ ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
9749
+ });
9750
+ });
9703
9751
  if (model.drawings) model.drawings.forEach((drawing) => {
9704
9752
  xmlStream.leafNode("Override", {
9705
9753
  PartName: `/xl/drawings/${drawing.name}.xml`,
9706
9754
  ContentType: "application/vnd.openxmlformats-officedocument.drawing+xml"
9707
9755
  });
9708
9756
  });
9709
- if (model.commentRefs) {
9757
+ if (model.commentRefs && model.commentRefs.length) {
9710
9758
  xmlStream.leafNode("Default", {
9711
9759
  Extension: "vml",
9712
9760
  ContentType: "application/vnd.openxmlformats-officedocument.vmlDrawing"
@@ -9955,9 +10003,9 @@ function extractRanges(parsedText) {
9955
10003
  var WorksheetXform = class extends BaseXform {
9956
10004
  render(xmlStream, model) {
9957
10005
  xmlStream.leafNode("sheet", {
9958
- sheetId: model.id,
9959
10006
  name: model.name,
9960
- state: model.state,
10007
+ sheetId: model.id,
10008
+ state: model.state === "visible" ? void 0 : model.state,
9961
10009
  "r:id": model.rId
9962
10010
  });
9963
10011
  }
@@ -10027,7 +10075,6 @@ var WorkbookPropertiesXform = class extends BaseXform {
10027
10075
  render(xmlStream, model) {
10028
10076
  xmlStream.leafNode("workbookPr", {
10029
10077
  date1904: model.date1904 ? 1 : void 0,
10030
- defaultThemeVersion: 164011,
10031
10078
  filterPrivacy: 1
10032
10079
  });
10033
10080
  }
@@ -10724,7 +10771,6 @@ var RowXform = class extends BaseXform {
10724
10771
  xmlStream.addAttribute("s", model.styleId);
10725
10772
  xmlStream.addAttribute("customFormat", "1");
10726
10773
  }
10727
- xmlStream.addAttribute("x14ac:dyDescent", "0.25");
10728
10774
  if (model.outlineLevel) xmlStream.addAttribute("outlineLevel", model.outlineLevel);
10729
10775
  if (model.collapsed) xmlStream.addAttribute("collapsed", "1");
10730
10776
  const cellXform = this.map.c;
@@ -11257,9 +11303,9 @@ var SheetFormatPropertiesXform = class extends BaseXform {
11257
11303
  if (model) {
11258
11304
  const attributes = {
11259
11305
  defaultRowHeight: model.defaultRowHeight,
11260
- outlineLevelRow: model.outlineLevelRow,
11261
- outlineLevelCol: model.outlineLevelCol,
11262
- "x14ac:dyDescent": model.dyDescent
11306
+ outlineLevelRow: model.outlineLevelRow || void 0,
11307
+ outlineLevelCol: model.outlineLevelCol || void 0,
11308
+ "x14ac:dyDescent": model.dyDescent || void 0
11263
11309
  };
11264
11310
  if (model.defaultColWidth) attributes.defaultColWidth = model.defaultColWidth;
11265
11311
  if (!model.defaultRowHeight || model.defaultRowHeight !== 15) attributes.customHeight = "1";
@@ -11306,12 +11352,14 @@ var SheetViewXform = class extends BaseXform {
11306
11352
  }
11307
11353
  }
11308
11354
  render(xmlStream, model) {
11309
- xmlStream.openNode("sheetView", { workbookViewId: model.workbookViewId || 0 });
11355
+ const initialAttrs = {};
11356
+ if (model.tabSelected) initialAttrs.tabSelected = "1";
11357
+ initialAttrs.workbookViewId = model.workbookViewId || 0;
11358
+ xmlStream.openNode("sheetView", initialAttrs);
11310
11359
  const add = function(name, value, included) {
11311
11360
  if (included) xmlStream.addAttribute(name, value);
11312
11361
  };
11313
11362
  add("rightToLeft", "1", model.rightToLeft === true);
11314
- add("tabSelected", "1", model.tabSelected);
11315
11363
  add("showRuler", "0", model.showRuler === false);
11316
11364
  add("showRowColHeaders", "0", model.showRowColHeaders === false);
11317
11365
  add("showGridLines", "0", model.showGridLines === false);
@@ -11611,9 +11659,9 @@ var PageSetupXform = class extends BaseXform {
11611
11659
  draft: booleanToXml$1(model.draft),
11612
11660
  cellComments: cellCommentsToXml(model.cellComments),
11613
11661
  errors: errorsToXml(model.errors),
11614
- scale: model.scale,
11615
- fitToWidth: model.fitToWidth,
11616
- fitToHeight: model.fitToHeight,
11662
+ scale: model.scale !== 100 ? model.scale : void 0,
11663
+ fitToWidth: model.fitToWidth !== 1 ? model.fitToWidth : void 0,
11664
+ fitToHeight: model.fitToHeight !== 1 ? model.fitToHeight : void 0,
11617
11665
  firstPageNumber: model.firstPageNumber,
11618
11666
  useFirstPageNumber: booleanToXml$1(!!model.firstPageNumber),
11619
11667
  usePrinterDefaults: booleanToXml$1(model.usePrinterDefaults),
@@ -13005,8 +13053,8 @@ var WorkSheetXform = class WorkSheetXform extends BaseXform {
13005
13053
  xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
13006
13054
  "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
13007
13055
  "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
13008
- "mc:Ignorable": "x14ac",
13009
- "xmlns:x14ac": "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"
13056
+ "xmlns:x14ac": "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac",
13057
+ "mc:Ignorable": "x14ac"
13010
13058
  };
13011
13059
  }
13012
13060
  constructor(options) {
@@ -14273,7 +14321,7 @@ var TableColumnXform = class extends BaseXform {
14273
14321
  id: model.id.toString(),
14274
14322
  name: model.name,
14275
14323
  totalsRowLabel: model.totalsRowLabel,
14276
- totalsRowFunction: model.totalsRowFunction,
14324
+ totalsRowFunction: model.totalsRowFunction === "none" ? void 0 : model.totalsRowFunction,
14277
14325
  dxfId: model.dxfId
14278
14326
  });
14279
14327
  }
@@ -14379,8 +14427,7 @@ var TableXform = class TableXform extends BaseXform {
14379
14427
  displayName: model.displayName || model.name,
14380
14428
  ref: model.tableRef,
14381
14429
  totalsRowCount: model.totalsRow ? "1" : void 0,
14382
- totalsRowShown: model.totalsRow ? void 0 : "1",
14383
- headerRowCount: model.headerRow ? "1" : "0"
14430
+ headerRowCount: model.headerRow ? void 0 : "0"
14384
14431
  });
14385
14432
  this.map.autoFilter.render(xmlStream, model);
14386
14433
  this.map.tableColumns.render(xmlStream, model.columns);
@@ -14401,7 +14448,7 @@ var TableXform = class TableXform extends BaseXform {
14401
14448
  displayName: attributes.displayName || attributes.name,
14402
14449
  tableRef: attributes.ref,
14403
14450
  totalsRow: attributes.totalsRowCount === "1",
14404
- headerRow: attributes.headerRowCount === "1"
14451
+ headerRow: attributes.headerRowCount !== "0"
14405
14452
  };
14406
14453
  break;
14407
14454
  default:
@@ -14441,13 +14488,7 @@ var TableXform = class TableXform extends BaseXform {
14441
14488
  });
14442
14489
  }
14443
14490
  static {
14444
- this.TABLE_ATTRIBUTES = {
14445
- xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
14446
- "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
14447
- "mc:Ignorable": "xr xr3",
14448
- "xmlns:xr": "http://schemas.microsoft.com/office/spreadsheetml/2014/revision",
14449
- "xmlns:xr3": "http://schemas.microsoft.com/office/spreadsheetml/2016/revision3"
14450
- };
14491
+ this.TABLE_ATTRIBUTES = { xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main" };
14451
14492
  }
14452
14493
  };
14453
14494
 
@@ -14631,14 +14672,16 @@ var PivotCacheRecordsXform = class PivotCacheRecordsXform extends BaseXform {
14631
14672
  //#endregion
14632
14673
  //#region src/xlsx/xform/pivot-table/cache-field.ts
14633
14674
  var CacheField = class {
14634
- constructor({ name, sharedItems }) {
14675
+ constructor({ name, sharedItems, minValue, maxValue }) {
14635
14676
  this.name = name;
14636
14677
  this.sharedItems = sharedItems;
14678
+ this.minValue = minValue;
14679
+ this.maxValue = maxValue;
14637
14680
  }
14638
14681
  render() {
14639
14682
  const escapedName = xmlEncode(this.name);
14640
14683
  if (this.sharedItems === null) return `<cacheField name="${escapedName}" numFmtId="0">
14641
- <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1" />
14684
+ <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1"${this.minValue !== void 0 && this.maxValue !== void 0 ? ` minValue="${this.minValue}" maxValue="${this.maxValue}"` : ""} />
14642
14685
  </cacheField>`;
14643
14686
  return `<cacheField name="${escapedName}" numFmtId="0">
14644
14687
  <sharedItems count="${this.sharedItems.length}">
@@ -14787,17 +14830,16 @@ var PivotCacheDefinitionXform = class PivotCacheDefinitionXform extends BaseXfor
14787
14830
  */
14788
14831
  renderNew(xmlStream, model) {
14789
14832
  const { source, cacheFields } = model;
14833
+ const recordCount = source.getSheetValues().slice(2).length;
14790
14834
  xmlStream.openXml(XmlStream.StdDocAttributes);
14791
14835
  xmlStream.openNode(this.tag, {
14792
14836
  ...PivotCacheDefinitionXform.PIVOT_CACHE_DEFINITION_ATTRIBUTES,
14793
14837
  "r:id": "rId1",
14794
14838
  refreshOnLoad: "1",
14795
- refreshedBy: "Author",
14796
- refreshedDate: "45125.026046874998",
14797
14839
  createdVersion: "8",
14798
14840
  refreshedVersion: "8",
14799
14841
  minRefreshableVersion: "3",
14800
- recordCount: cacheFields.length + 1
14842
+ recordCount
14801
14843
  });
14802
14844
  xmlStream.openNode("cacheSource", { type: "worksheet" });
14803
14845
  xmlStream.leafNode("worksheetSource", {
@@ -14820,8 +14862,6 @@ var PivotCacheDefinitionXform = class PivotCacheDefinitionXform extends BaseXfor
14820
14862
  ...PivotCacheDefinitionXform.PIVOT_CACHE_DEFINITION_ATTRIBUTES,
14821
14863
  "r:id": model.rId || "rId1",
14822
14864
  refreshOnLoad: model.refreshOnLoad || "1",
14823
- refreshedBy: model.refreshedBy || "Author",
14824
- refreshedDate: model.refreshedDate || "45125.026046874998",
14825
14865
  createdVersion: model.createdVersion || "8",
14826
14866
  refreshedVersion: model.refreshedVersion || "8",
14827
14867
  minRefreshableVersion: model.minRefreshableVersion || "3",
@@ -14851,8 +14891,6 @@ var PivotCacheDefinitionXform = class PivotCacheDefinitionXform extends BaseXfor
14851
14891
  cacheFields: [],
14852
14892
  rId: attributes["r:id"],
14853
14893
  refreshOnLoad: attributes.refreshOnLoad,
14854
- refreshedBy: attributes.refreshedBy,
14855
- refreshedDate: attributes.refreshedDate,
14856
14894
  createdVersion: attributes.createdVersion,
14857
14895
  refreshedVersion: attributes.refreshedVersion,
14858
14896
  minRefreshableVersion: attributes.minRefreshableVersion,
@@ -14907,10 +14945,7 @@ var PivotCacheDefinitionXform = class PivotCacheDefinitionXform extends BaseXfor
14907
14945
  static {
14908
14946
  this.PIVOT_CACHE_DEFINITION_ATTRIBUTES = {
14909
14947
  xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
14910
- "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
14911
- "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
14912
- "mc:Ignorable": "xr",
14913
- "xmlns:xr": "http://schemas.microsoft.com/office/spreadsheetml/2014/revision"
14948
+ "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
14914
14949
  };
14915
14950
  }
14916
14951
  };
@@ -14963,11 +14998,16 @@ var PivotTableXform = class PivotTableXform extends BaseXform {
14963
14998
  */
14964
14999
  renderNew(xmlStream, model) {
14965
15000
  const { rows, columns, values, cacheFields, cacheId, applyWidthHeightFormats } = model;
14966
- const uniqueUid = `{${crypto.randomUUID().toUpperCase()}}`;
15001
+ const rowItems = buildRowItems(rows, cacheFields);
15002
+ const colItems = buildColItems(columns, cacheFields, values.length);
15003
+ const rowFieldItemCount = rows.length > 0 ? cacheFields[rows[0]]?.sharedItems?.length || 0 : 0;
15004
+ const colFieldItemCount = columns.length > 0 ? cacheFields[columns[0]]?.sharedItems?.length || 0 : 0;
15005
+ const endRow = 4 + rowFieldItemCount + 1;
15006
+ const endCol = 1 + colFieldItemCount + 1;
15007
+ const locationRef = `A3:${String.fromCharCode(64 + endCol)}${endRow}`;
14967
15008
  xmlStream.openXml(XmlStream.StdDocAttributes);
14968
15009
  xmlStream.openNode(this.tag, {
14969
15010
  ...PivotTableXform.PIVOT_TABLE_ATTRIBUTES,
14970
- "xr:uid": uniqueUid,
14971
15011
  name: "PivotTable2",
14972
15012
  cacheId,
14973
15013
  applyNumberFormats: "0",
@@ -14988,21 +15028,21 @@ var PivotTableXform = class PivotTableXform extends BaseXform {
14988
15028
  multipleFieldFilters: "0"
14989
15029
  });
14990
15030
  xmlStream.writeXml(`
14991
- <location ref="A3:E15" firstHeaderRow="1" firstDataRow="2" firstDataCol="1" />
15031
+ <location ref="${locationRef}" firstHeaderRow="1" firstDataRow="2" firstDataCol="1" />
14992
15032
  <pivotFields count="${cacheFields.length}">
14993
15033
  ${renderPivotFields(model)}
14994
15034
  </pivotFields>
14995
15035
  <rowFields count="${rows.length}">
14996
15036
  ${rows.map((rowIndex) => `<field x="${rowIndex}" />`).join("\n ")}
14997
15037
  </rowFields>
14998
- <rowItems count="1">
14999
- <i t="grand"><x /></i>
15038
+ <rowItems count="${rowItems.count}">
15039
+ ${rowItems.xml}
15000
15040
  </rowItems>
15001
15041
  <colFields count="${columns.length === 0 ? 1 : columns.length}">
15002
15042
  ${columns.length === 0 ? "<field x=\"-2\" />" : columns.map((columnIndex) => `<field x="${columnIndex}" />`).join("\n ")}
15003
15043
  </colFields>
15004
- <colItems count="1">
15005
- <i t="grand"><x /></i>
15044
+ <colItems count="${colItems.count}">
15045
+ ${colItems.xml}
15006
15046
  </colItems>
15007
15047
  <dataFields count="${values.length}">
15008
15048
  ${buildDataFields(cacheFields, values, model.metric)}
@@ -15042,11 +15082,9 @@ var PivotTableXform = class PivotTableXform extends BaseXform {
15042
15082
  * Render loaded pivot table (preserving original structure)
15043
15083
  */
15044
15084
  renderLoaded(xmlStream, model) {
15045
- const uniqueUid = model.uid || `{${crypto.randomUUID().toUpperCase()}}`;
15046
15085
  xmlStream.openXml(XmlStream.StdDocAttributes);
15047
15086
  xmlStream.openNode(this.tag, {
15048
15087
  ...PivotTableXform.PIVOT_TABLE_ATTRIBUTES,
15049
- "xr:uid": uniqueUid,
15050
15088
  name: model.name || "PivotTable1",
15051
15089
  cacheId: model.cacheId,
15052
15090
  applyNumberFormats: model.applyNumberFormats || "0",
@@ -15295,15 +15333,64 @@ var PivotTableXform = class PivotTableXform extends BaseXform {
15295
15333
  }
15296
15334
  reconcile(_model, _options) {}
15297
15335
  static {
15298
- this.PIVOT_TABLE_ATTRIBUTES = {
15299
- xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
15300
- "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
15301
- "mc:Ignorable": "xr",
15302
- "xmlns:xr": "http://schemas.microsoft.com/office/spreadsheetml/2014/revision"
15303
- };
15336
+ this.PIVOT_TABLE_ATTRIBUTES = { xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main" };
15304
15337
  }
15305
15338
  };
15306
15339
  /**
15340
+ * Build rowItems XML - one item for each unique value in row fields, plus grand total.
15341
+ * Each <i> represents a row in the pivot table.
15342
+ * - Regular items: <i><x/></i> for index 0, <i><x v="index"/></i> for index > 0
15343
+ * - Grand total: <i t="grand"><x/></i>
15344
+ * Note: When v=0, the v attribute should be omitted (Excel convention)
15345
+ */
15346
+ function buildRowItems(rows, cacheFields) {
15347
+ if (rows.length === 0) return {
15348
+ count: 1,
15349
+ xml: "<i t=\"grand\"><x /></i>"
15350
+ };
15351
+ const itemCount = (cacheFields[rows[0]]?.sharedItems || []).length;
15352
+ const items = [];
15353
+ for (let i = 0; i < itemCount; i++) if (i === 0) items.push("<i><x /></i>");
15354
+ else items.push(`<i><x v="${i}" /></i>`);
15355
+ items.push("<i t=\"grand\"><x /></i>");
15356
+ return {
15357
+ count: items.length,
15358
+ xml: items.join("\n ")
15359
+ };
15360
+ }
15361
+ /**
15362
+ * Build colItems XML - one item for each unique value in column fields, plus grand total.
15363
+ * When there are multiple data fields (values), each column value may have sub-columns.
15364
+ * Note: When v=0, the v attribute should be omitted (Excel convention)
15365
+ */
15366
+ function buildColItems(columns, cacheFields, valueCount) {
15367
+ if (columns.length === 0) {
15368
+ if (valueCount > 1) {
15369
+ const items$1 = [];
15370
+ for (let i = 0; i < valueCount; i++) if (i === 0) items$1.push("<i><x /></i>");
15371
+ else items$1.push(`<i><x v="${i}" /></i>`);
15372
+ items$1.push("<i t=\"grand\"><x /></i>");
15373
+ return {
15374
+ count: items$1.length,
15375
+ xml: items$1.join("\n ")
15376
+ };
15377
+ }
15378
+ return {
15379
+ count: 1,
15380
+ xml: "<i t=\"grand\"><x /></i>"
15381
+ };
15382
+ }
15383
+ const itemCount = (cacheFields[columns[0]]?.sharedItems || []).length;
15384
+ const items = [];
15385
+ for (let i = 0; i < itemCount; i++) if (i === 0) items.push("<i><x /></i>");
15386
+ else items.push(`<i><x v="${i}" /></i>`);
15387
+ items.push("<i t=\"grand\"><x /></i>");
15388
+ return {
15389
+ count: items.length,
15390
+ xml: items.join("\n ")
15391
+ };
15392
+ }
15393
+ /**
15307
15394
  * Build dataField XML elements for all values in the pivot table.
15308
15395
  * Supports multiple values when columns is empty.
15309
15396
  */
@@ -15326,18 +15413,22 @@ function renderPivotFields(pivotTable) {
15326
15413
  }).join("");
15327
15414
  }
15328
15415
  function renderPivotField(fieldType, sharedItems) {
15329
- const defaultAttributes = "compact=\"0\" outline=\"0\" showAll=\"0\" defaultSubtotal=\"0\"";
15330
- if (fieldType === "row" || fieldType === "column") return `
15331
- <pivotField axis="${fieldType === "row" ? "axisRow" : "axisCol"}" ${defaultAttributes}>
15416
+ if (fieldType === "row" || fieldType === "column") {
15417
+ const axis = fieldType === "row" ? "axisRow" : "axisCol";
15418
+ const axisAttributes = "compact=\"0\" outline=\"0\" showAll=\"0\"";
15419
+ const itemsXml = [...sharedItems.map((_item, index) => `<item x="${index}" />`), "<item t=\"default\" />"].join("\n ");
15420
+ return `
15421
+ <pivotField axis="${axis}" ${axisAttributes}>
15332
15422
  <items count="${sharedItems.length + 1}">
15333
- ${sharedItems.map((_item, index) => `<item x="${index}" />`).join("\n ")}
15423
+ ${itemsXml}
15334
15424
  </items>
15335
15425
  </pivotField>
15336
15426
  `;
15427
+ }
15337
15428
  return `
15338
15429
  <pivotField
15339
15430
  ${fieldType === "value" ? "dataField=\"1\"" : ""}
15340
- ${defaultAttributes}
15431
+ compact="0" outline="0" showAll="0" defaultSubtotal="0"
15341
15432
  />
15342
15433
  `;
15343
15434
  }
@@ -16782,13 +16873,6 @@ const AUTO_DETECT = [
16782
16873
  [25, [parseISOOffset]],
16783
16874
  [29, [parseISOMsOffset]]
16784
16875
  ];
16785
- function tzOffset(d) {
16786
- const off = -d.getTimezoneOffset();
16787
- const sign = off >= 0 ? "+" : "-";
16788
- const h = Math.abs(off) / 60 | 0;
16789
- const m = Math.abs(off) % 60;
16790
- return `${sign}${PAD2[h]}:${PAD2[m]}`;
16791
- }
16792
16876
  /**
16793
16877
  * Optimized date parser for batch processing
16794
16878
  *
@@ -16842,6 +16926,13 @@ var DateParser = class DateParser {
16842
16926
  return out;
16843
16927
  }
16844
16928
  };
16929
+ function tzOffset(d) {
16930
+ const off = -d.getTimezoneOffset();
16931
+ const sign = off >= 0 ? "+" : "-";
16932
+ const h = Math.abs(off) / 60 | 0;
16933
+ const m = Math.abs(off) % 60;
16934
+ return `${sign}${PAD2[h]}:${PAD2[m]}`;
16935
+ }
16845
16936
  /**
16846
16937
  * Optimized date formatter for batch processing
16847
16938
  *