@cj-tech-master/excelts 2.0.1 → 3.0.0-canary.20251228183403.d3eb98d

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 (58) hide show
  1. package/dist/browser/excelts.esm.js +181 -133
  2. package/dist/browser/excelts.esm.js.map +1 -1
  3. package/dist/browser/excelts.esm.min.js +30 -24
  4. package/dist/browser/excelts.iife.js +181 -133
  5. package/dist/browser/excelts.iife.js.map +1 -1
  6. package/dist/browser/excelts.iife.min.js +30 -24
  7. package/dist/cjs/doc/pivot-table.js +47 -6
  8. package/dist/cjs/doc/worksheet.js +0 -1
  9. package/dist/cjs/stream/xlsx/worksheet-writer.js +0 -1
  10. package/dist/cjs/xlsx/xform/book/sheet-xform.js +3 -2
  11. package/dist/cjs/xlsx/xform/book/workbook-properties-xform.js +1 -1
  12. package/dist/cjs/xlsx/xform/core/content-types-xform.js +12 -6
  13. package/dist/cjs/xlsx/xform/pivot-table/cache-field-xform.js +17 -21
  14. package/dist/cjs/xlsx/xform/pivot-table/cache-field.js +43 -7
  15. package/dist/cjs/xlsx/xform/pivot-table/pivot-cache-definition-xform.js +1 -10
  16. package/dist/cjs/xlsx/xform/pivot-table/pivot-cache-records-xform.js +1 -1
  17. package/dist/cjs/xlsx/xform/pivot-table/pivot-table-xform.js +51 -30
  18. package/dist/cjs/xlsx/xform/sheet/page-setup-xform.js +4 -3
  19. package/dist/cjs/xlsx/xform/sheet/row-xform.js +1 -1
  20. package/dist/cjs/xlsx/xform/sheet/sheet-format-properties-xform.js +6 -3
  21. package/dist/cjs/xlsx/xform/sheet/sheet-view-xform.js +8 -4
  22. package/dist/cjs/xlsx/xform/sheet/worksheet-xform.js +2 -2
  23. package/dist/cjs/xlsx/xform/style/font-xform.js +36 -23
  24. package/dist/cjs/xlsx/xform/table/auto-filter-xform.js +3 -1
  25. package/dist/cjs/xlsx/xform/table/table-column-xform.js +2 -1
  26. package/dist/cjs/xlsx/xform/table/table-xform.js +5 -9
  27. package/dist/esm/doc/pivot-table.js +47 -6
  28. package/dist/esm/doc/worksheet.js +0 -1
  29. package/dist/esm/stream/xlsx/worksheet-writer.js +0 -1
  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-xform.js +17 -21
  34. package/dist/esm/xlsx/xform/pivot-table/cache-field.js +43 -7
  35. package/dist/esm/xlsx/xform/pivot-table/pivot-cache-definition-xform.js +1 -10
  36. package/dist/esm/xlsx/xform/pivot-table/pivot-cache-records-xform.js +1 -1
  37. package/dist/esm/xlsx/xform/pivot-table/pivot-table-xform.js +51 -30
  38. package/dist/esm/xlsx/xform/sheet/page-setup-xform.js +4 -3
  39. package/dist/esm/xlsx/xform/sheet/row-xform.js +1 -1
  40. package/dist/esm/xlsx/xform/sheet/sheet-format-properties-xform.js +6 -3
  41. package/dist/esm/xlsx/xform/sheet/sheet-view-xform.js +8 -4
  42. package/dist/esm/xlsx/xform/sheet/worksheet-xform.js +2 -2
  43. package/dist/esm/xlsx/xform/style/font-xform.js +36 -23
  44. package/dist/esm/xlsx/xform/table/auto-filter-xform.js +3 -1
  45. package/dist/esm/xlsx/xform/table/table-column-xform.js +2 -1
  46. package/dist/esm/xlsx/xform/table/table-xform.js +5 -9
  47. package/dist/types/doc/pivot-table.d.ts +5 -1
  48. package/dist/types/stream/xlsx/worksheet-writer.d.ts +1 -1
  49. package/dist/types/types.d.ts +1 -1
  50. package/dist/types/xlsx/xform/pivot-table/cache-field-xform.d.ts +1 -1
  51. package/dist/types/xlsx/xform/pivot-table/cache-field.d.ts +6 -2
  52. package/dist/types/xlsx/xform/pivot-table/pivot-cache-definition-xform.d.ts +0 -5
  53. package/dist/types/xlsx/xform/pivot-table/pivot-table-xform.d.ts +0 -3
  54. package/dist/types/xlsx/xform/sheet/sheet-format-properties-xform.d.ts +1 -1
  55. package/dist/types/xlsx/xform/sheet/worksheet-xform.d.ts +1 -1
  56. package/dist/types/xlsx/xform/style/font-xform.d.ts +1 -0
  57. package/dist/types/xlsx/xform/table/table-xform.d.ts +0 -4
  58. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @cj-tech-master/excelts v2.0.1
2
+ * @cj-tech-master/excelts v3.0.0-canary.20251228183403.d3eb98d
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;
@@ -3002,7 +3002,7 @@ var ExcelTS = (function(exports) {
3002
3002
  validate(worksheet, model, source);
3003
3003
  const { rows, values } = model;
3004
3004
  const columns = model.columns ?? [];
3005
- const cacheFields = makeCacheFields(source, [...rows, ...columns]);
3005
+ const cacheFields = makeCacheFields(source, [...rows, ...columns], values);
3006
3006
  const nameToIndex = cacheFields.reduce((result, cacheField, index) => {
3007
3007
  result[cacheField.name] = index;
3008
3008
  return result;
@@ -3037,9 +3037,10 @@ var ExcelTS = (function(exports) {
3037
3037
  if (model.values.length < 1) throw new Error("Must have at least one value.");
3038
3038
  if (model.values.length > 1 && columns.length > 0) throw new Error("It is currently not possible to have multiple values when columns are specified. Please either supply an empty array for columns or a single value.");
3039
3039
  }
3040
- function makeCacheFields(source, fieldNamesWithSharedItems) {
3040
+ function makeCacheFields(source, fieldNamesWithSharedItems, valueFieldNames) {
3041
3041
  const names = source.getRow(1).values;
3042
3042
  const sharedItemsFields = new Set(fieldNamesWithSharedItems);
3043
+ const valueFields = new Set(valueFieldNames);
3043
3044
  const aggregate = (columnIndex) => {
3044
3045
  const columnValues = source.getColumn(columnIndex).values;
3045
3046
  const uniqueValues = /* @__PURE__ */ new Set();
@@ -3049,13 +3050,42 @@ var ExcelTS = (function(exports) {
3049
3050
  }
3050
3051
  return toSortedArray(uniqueValues);
3051
3052
  };
3053
+ const getMinMax = (columnIndex) => {
3054
+ const columnValues = source.getColumn(columnIndex).values;
3055
+ let min = Infinity;
3056
+ let max = -Infinity;
3057
+ let hasNumeric = false;
3058
+ for (let i = 2; i < columnValues.length; i++) {
3059
+ const v = columnValues[i];
3060
+ if (typeof v === "number" && !isNaN(v)) {
3061
+ hasNumeric = true;
3062
+ if (v < min) min = v;
3063
+ if (v > max) max = v;
3064
+ }
3065
+ }
3066
+ return hasNumeric ? {
3067
+ minValue: min,
3068
+ maxValue: max
3069
+ } : null;
3070
+ };
3052
3071
  const result = [];
3053
3072
  for (const columnIndex of range(1, names.length)) {
3054
3073
  const name = names[columnIndex];
3055
- const sharedItems = sharedItemsFields.has(name) ? aggregate(columnIndex) : null;
3056
- result.push({
3074
+ if (sharedItemsFields.has(name)) result.push({
3057
3075
  name,
3058
- sharedItems
3076
+ sharedItems: aggregate(columnIndex)
3077
+ });
3078
+ else if (valueFields.has(name)) {
3079
+ const minMax = getMinMax(columnIndex);
3080
+ result.push({
3081
+ name,
3082
+ sharedItems: null,
3083
+ minValue: minMax?.minValue,
3084
+ maxValue: minMax?.maxValue
3085
+ });
3086
+ } else result.push({
3087
+ name,
3088
+ sharedItems: null
3059
3089
  });
3060
3090
  }
3061
3091
  return result;
@@ -3118,7 +3148,6 @@ var ExcelTS = (function(exports) {
3118
3148
  this.colBreaks = [];
3119
3149
  this.properties = Object.assign({}, {
3120
3150
  defaultRowHeight: 15,
3121
- dyDescent: 55,
3122
3151
  outlineLevelCol: 0,
3123
3152
  outlineLevelRow: 0
3124
3153
  }, options.properties);
@@ -7492,116 +7521,136 @@ var ExcelTS = (function(exports) {
7492
7521
  constructor(options) {
7493
7522
  super();
7494
7523
  this.options = options || FontXform.OPTIONS;
7495
- this.map = {
7496
- b: {
7524
+ const fontProperties = [
7525
+ {
7526
+ tag: "b",
7497
7527
  prop: "bold",
7498
7528
  xform: new BooleanXform({
7499
7529
  tag: "b",
7500
7530
  attr: "val"
7501
7531
  })
7502
7532
  },
7503
- i: {
7533
+ {
7534
+ tag: "i",
7504
7535
  prop: "italic",
7505
7536
  xform: new BooleanXform({
7506
7537
  tag: "i",
7507
7538
  attr: "val"
7508
7539
  })
7509
7540
  },
7510
- u: {
7541
+ {
7542
+ tag: "u",
7511
7543
  prop: "underline",
7512
7544
  xform: new UnderlineXform()
7513
7545
  },
7514
- charset: {
7515
- prop: "charset",
7516
- xform: new IntegerXform({
7517
- tag: "charset",
7546
+ {
7547
+ tag: "strike",
7548
+ prop: "strike",
7549
+ xform: new BooleanXform({
7550
+ tag: "strike",
7518
7551
  attr: "val"
7519
7552
  })
7520
7553
  },
7521
- color: {
7522
- prop: "color",
7523
- xform: new ColorXform()
7524
- },
7525
- condense: {
7554
+ {
7555
+ tag: "condense",
7526
7556
  prop: "condense",
7527
7557
  xform: new BooleanXform({
7528
7558
  tag: "condense",
7529
7559
  attr: "val"
7530
7560
  })
7531
7561
  },
7532
- extend: {
7562
+ {
7563
+ tag: "extend",
7533
7564
  prop: "extend",
7534
7565
  xform: new BooleanXform({
7535
7566
  tag: "extend",
7536
7567
  attr: "val"
7537
7568
  })
7538
7569
  },
7539
- family: {
7540
- prop: "family",
7541
- xform: new IntegerXform({
7542
- tag: "family",
7570
+ {
7571
+ tag: "outline",
7572
+ prop: "outline",
7573
+ xform: new BooleanXform({
7574
+ tag: "outline",
7543
7575
  attr: "val"
7544
7576
  })
7545
7577
  },
7546
- outline: {
7547
- prop: "outline",
7578
+ {
7579
+ tag: "shadow",
7580
+ prop: "shadow",
7548
7581
  xform: new BooleanXform({
7549
- tag: "outline",
7582
+ tag: "shadow",
7550
7583
  attr: "val"
7551
7584
  })
7552
7585
  },
7553
- vertAlign: {
7554
- prop: "vertAlign",
7555
- xform: new StringXform({
7556
- tag: "vertAlign",
7586
+ {
7587
+ tag: "sz",
7588
+ prop: "size",
7589
+ xform: new IntegerXform({
7590
+ tag: "sz",
7557
7591
  attr: "val"
7558
7592
  })
7559
7593
  },
7560
- scheme: {
7561
- prop: "scheme",
7594
+ {
7595
+ tag: "color",
7596
+ prop: "color",
7597
+ xform: new ColorXform()
7598
+ },
7599
+ {
7600
+ tag: this.options.fontNameTag,
7601
+ prop: "name",
7562
7602
  xform: new StringXform({
7563
- tag: "scheme",
7603
+ tag: this.options.fontNameTag,
7564
7604
  attr: "val"
7565
7605
  })
7566
7606
  },
7567
- shadow: {
7568
- prop: "shadow",
7569
- xform: new BooleanXform({
7570
- tag: "shadow",
7607
+ {
7608
+ tag: "family",
7609
+ prop: "family",
7610
+ xform: new IntegerXform({
7611
+ tag: "family",
7571
7612
  attr: "val"
7572
7613
  })
7573
7614
  },
7574
- strike: {
7575
- prop: "strike",
7576
- xform: new BooleanXform({
7577
- tag: "strike",
7615
+ {
7616
+ tag: "scheme",
7617
+ prop: "scheme",
7618
+ xform: new StringXform({
7619
+ tag: "scheme",
7578
7620
  attr: "val"
7579
7621
  })
7580
7622
  },
7581
- sz: {
7582
- prop: "size",
7623
+ {
7624
+ tag: "charset",
7625
+ prop: "charset",
7583
7626
  xform: new IntegerXform({
7584
- tag: "sz",
7627
+ tag: "charset",
7628
+ attr: "val"
7629
+ })
7630
+ },
7631
+ {
7632
+ tag: "vertAlign",
7633
+ prop: "vertAlign",
7634
+ xform: new StringXform({
7635
+ tag: "vertAlign",
7585
7636
  attr: "val"
7586
7637
  })
7587
7638
  }
7588
- };
7589
- this.map[this.options.fontNameTag] = {
7590
- prop: "name",
7591
- xform: new StringXform({
7592
- tag: this.options.fontNameTag,
7593
- attr: "val"
7594
- })
7595
- };
7639
+ ];
7640
+ this.map = Object.fromEntries(fontProperties.map((p) => [p.tag, {
7641
+ prop: p.prop,
7642
+ xform: p.xform
7643
+ }]));
7644
+ this.renderOrder = fontProperties.map((p) => p.tag);
7596
7645
  }
7597
7646
  get tag() {
7598
7647
  return this.options.tagName;
7599
7648
  }
7600
7649
  render(xmlStream, model) {
7601
- const { map } = this;
7650
+ const { map, renderOrder } = this;
7602
7651
  xmlStream.openNode(this.options.tagName);
7603
- Object.entries(this.map).forEach(([tag, defn]) => {
7604
- map[tag].xform.render(xmlStream, model[defn.prop]);
7652
+ renderOrder.forEach((tag) => {
7653
+ map[tag].xform.render(xmlStream, model[map[tag].prop]);
7605
7654
  });
7606
7655
  xmlStream.closeNode();
7607
7656
  }
@@ -9680,10 +9729,6 @@ var ExcelTS = (function(exports) {
9680
9729
  PartName: `/xl/pivotCache/pivotCacheRecords${n}.xml`,
9681
9730
  ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml"
9682
9731
  });
9683
- xmlStream.leafNode("Override", {
9684
- PartName: `/xl/pivotTables/pivotTable${n}.xml`,
9685
- ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
9686
- });
9687
9732
  });
9688
9733
  xmlStream.leafNode("Override", {
9689
9734
  PartName: "/xl/theme/theme1.xml",
@@ -9703,13 +9748,20 @@ var ExcelTS = (function(exports) {
9703
9748
  ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
9704
9749
  });
9705
9750
  });
9751
+ if ((model.pivotTables || []).length) (model.pivotTables || []).forEach((pivotTable) => {
9752
+ const n = pivotTable.tableNumber;
9753
+ xmlStream.leafNode("Override", {
9754
+ PartName: `/xl/pivotTables/pivotTable${n}.xml`,
9755
+ ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
9756
+ });
9757
+ });
9706
9758
  if (model.drawings) model.drawings.forEach((drawing) => {
9707
9759
  xmlStream.leafNode("Override", {
9708
9760
  PartName: `/xl/drawings/${drawing.name}.xml`,
9709
9761
  ContentType: "application/vnd.openxmlformats-officedocument.drawing+xml"
9710
9762
  });
9711
9763
  });
9712
- if (model.commentRefs) {
9764
+ if (model.commentRefs && model.commentRefs.length) {
9713
9765
  xmlStream.leafNode("Default", {
9714
9766
  Extension: "vml",
9715
9767
  ContentType: "application/vnd.openxmlformats-officedocument.vmlDrawing"
@@ -9958,9 +10010,9 @@ var ExcelTS = (function(exports) {
9958
10010
  var WorksheetXform = class extends BaseXform {
9959
10011
  render(xmlStream, model) {
9960
10012
  xmlStream.leafNode("sheet", {
9961
- sheetId: model.id,
9962
10013
  name: model.name,
9963
- state: model.state,
10014
+ sheetId: model.id,
10015
+ state: model.state === "visible" ? void 0 : model.state,
9964
10016
  "r:id": model.rId
9965
10017
  });
9966
10018
  }
@@ -10030,7 +10082,6 @@ var ExcelTS = (function(exports) {
10030
10082
  render(xmlStream, model) {
10031
10083
  xmlStream.leafNode("workbookPr", {
10032
10084
  date1904: model.date1904 ? 1 : void 0,
10033
- defaultThemeVersion: 164011,
10034
10085
  filterPrivacy: 1
10035
10086
  });
10036
10087
  }
@@ -10727,7 +10778,6 @@ var ExcelTS = (function(exports) {
10727
10778
  xmlStream.addAttribute("s", model.styleId);
10728
10779
  xmlStream.addAttribute("customFormat", "1");
10729
10780
  }
10730
- xmlStream.addAttribute("x14ac:dyDescent", "0.25");
10731
10781
  if (model.outlineLevel) xmlStream.addAttribute("outlineLevel", model.outlineLevel);
10732
10782
  if (model.collapsed) xmlStream.addAttribute("collapsed", "1");
10733
10783
  const cellXform = this.map.c;
@@ -11260,9 +11310,9 @@ var ExcelTS = (function(exports) {
11260
11310
  if (model) {
11261
11311
  const attributes = {
11262
11312
  defaultRowHeight: model.defaultRowHeight,
11263
- outlineLevelRow: model.outlineLevelRow,
11264
- outlineLevelCol: model.outlineLevelCol,
11265
- "x14ac:dyDescent": model.dyDescent
11313
+ outlineLevelRow: model.outlineLevelRow || void 0,
11314
+ outlineLevelCol: model.outlineLevelCol || void 0,
11315
+ "x14ac:dyDescent": model.dyDescent || void 0
11266
11316
  };
11267
11317
  if (model.defaultColWidth) attributes.defaultColWidth = model.defaultColWidth;
11268
11318
  if (!model.defaultRowHeight || model.defaultRowHeight !== 15) attributes.customHeight = "1";
@@ -11309,12 +11359,14 @@ var ExcelTS = (function(exports) {
11309
11359
  }
11310
11360
  }
11311
11361
  render(xmlStream, model) {
11312
- xmlStream.openNode("sheetView", { workbookViewId: model.workbookViewId || 0 });
11362
+ const initialAttrs = {};
11363
+ if (model.tabSelected) initialAttrs.tabSelected = "1";
11364
+ initialAttrs.workbookViewId = model.workbookViewId || 0;
11365
+ xmlStream.openNode("sheetView", initialAttrs);
11313
11366
  const add = function(name, value, included) {
11314
11367
  if (included) xmlStream.addAttribute(name, value);
11315
11368
  };
11316
11369
  add("rightToLeft", "1", model.rightToLeft === true);
11317
- add("tabSelected", "1", model.tabSelected);
11318
11370
  add("showRuler", "0", model.showRuler === false);
11319
11371
  add("showRowColHeaders", "0", model.showRowColHeaders === false);
11320
11372
  add("showGridLines", "0", model.showGridLines === false);
@@ -11614,9 +11666,9 @@ var ExcelTS = (function(exports) {
11614
11666
  draft: booleanToXml$1(model.draft),
11615
11667
  cellComments: cellCommentsToXml(model.cellComments),
11616
11668
  errors: errorsToXml(model.errors),
11617
- scale: model.scale,
11618
- fitToWidth: model.fitToWidth,
11619
- fitToHeight: model.fitToHeight,
11669
+ scale: model.scale !== 100 ? model.scale : void 0,
11670
+ fitToWidth: model.fitToWidth !== 1 ? model.fitToWidth : void 0,
11671
+ fitToHeight: model.fitToHeight !== 1 ? model.fitToHeight : void 0,
11620
11672
  firstPageNumber: model.firstPageNumber,
11621
11673
  useFirstPageNumber: booleanToXml$1(!!model.firstPageNumber),
11622
11674
  usePrinterDefaults: booleanToXml$1(model.usePrinterDefaults),
@@ -13008,8 +13060,8 @@ var ExcelTS = (function(exports) {
13008
13060
  xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
13009
13061
  "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
13010
13062
  "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"
13063
+ "xmlns:x14ac": "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac",
13064
+ "mc:Ignorable": "x14ac"
13013
13065
  };
13014
13066
  }
13015
13067
  constructor(options) {
@@ -14276,7 +14328,7 @@ var ExcelTS = (function(exports) {
14276
14328
  id: model.id.toString(),
14277
14329
  name: model.name,
14278
14330
  totalsRowLabel: model.totalsRowLabel,
14279
- totalsRowFunction: model.totalsRowFunction,
14331
+ totalsRowFunction: model.totalsRowFunction === "none" ? void 0 : model.totalsRowFunction,
14280
14332
  dxfId: model.dxfId
14281
14333
  });
14282
14334
  }
@@ -14382,8 +14434,7 @@ var ExcelTS = (function(exports) {
14382
14434
  displayName: model.displayName || model.name,
14383
14435
  ref: model.tableRef,
14384
14436
  totalsRowCount: model.totalsRow ? "1" : void 0,
14385
- totalsRowShown: model.totalsRow ? void 0 : "1",
14386
- headerRowCount: model.headerRow ? "1" : "0"
14437
+ headerRowCount: model.headerRow ? void 0 : "0"
14387
14438
  });
14388
14439
  this.map.autoFilter.render(xmlStream, model);
14389
14440
  this.map.tableColumns.render(xmlStream, model.columns);
@@ -14404,7 +14455,7 @@ var ExcelTS = (function(exports) {
14404
14455
  displayName: attributes.displayName || attributes.name,
14405
14456
  tableRef: attributes.ref,
14406
14457
  totalsRow: attributes.totalsRowCount === "1",
14407
- headerRow: attributes.headerRowCount === "1"
14458
+ headerRow: attributes.headerRowCount !== "0"
14408
14459
  };
14409
14460
  break;
14410
14461
  default:
@@ -14444,13 +14495,7 @@ var ExcelTS = (function(exports) {
14444
14495
  });
14445
14496
  }
14446
14497
  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
- };
14498
+ this.TABLE_ATTRIBUTES = { xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main" };
14454
14499
  }
14455
14500
  };
14456
14501
 
@@ -14634,15 +14679,33 @@ var ExcelTS = (function(exports) {
14634
14679
  //#endregion
14635
14680
  //#region src/xlsx/xform/pivot-table/cache-field.ts
14636
14681
  var CacheField = class {
14637
- constructor({ name, sharedItems }) {
14682
+ constructor({ name, sharedItems, minValue, maxValue }) {
14638
14683
  this.name = name;
14639
14684
  this.sharedItems = sharedItems;
14685
+ this.minValue = minValue;
14686
+ this.maxValue = maxValue;
14640
14687
  }
14641
14688
  render() {
14642
14689
  const escapedName = xmlEncode(this.name);
14643
- if (this.sharedItems === null) return `<cacheField name="${escapedName}" numFmtId="0">
14644
- <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1" />
14690
+ if (this.sharedItems === null) {
14691
+ if (this.minValue === void 0 || this.maxValue === void 0) return `<cacheField name="${escapedName}" numFmtId="0">
14692
+ <sharedItems />
14693
+ </cacheField>`;
14694
+ return `<cacheField name="${escapedName}" numFmtId="0">
14695
+ <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1" minValue="${this.minValue}" maxValue="${this.maxValue}" />
14645
14696
  </cacheField>`;
14697
+ }
14698
+ const allNumeric = this.sharedItems.length > 0 && this.sharedItems.every((item) => typeof item === "number" && Number.isFinite(item));
14699
+ const allInteger = allNumeric && this.sharedItems.every((item) => Number.isInteger(item));
14700
+ if (allNumeric) {
14701
+ const minValue = Math.min(...this.sharedItems);
14702
+ const maxValue = Math.max(...this.sharedItems);
14703
+ return `<cacheField name="${escapedName}" numFmtId="0">
14704
+ <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1"${allInteger ? " containsInteger=\"1\"" : ""} minValue="${minValue}" maxValue="${maxValue}" count="${this.sharedItems.length}">
14705
+ ${this.sharedItems.map((item) => `<n v="${item}" />`).join("")}
14706
+ </sharedItems>
14707
+ </cacheField>`;
14708
+ }
14646
14709
  return `<cacheField name="${escapedName}" numFmtId="0">
14647
14710
  <sharedItems count="${this.sharedItems.length}">
14648
14711
  ${this.sharedItems.map((item) => `<s v="${xmlEncode(String(item))}" />`).join("")}
@@ -14696,16 +14759,13 @@ var ExcelTS = (function(exports) {
14696
14759
  break;
14697
14760
  case "sharedItems":
14698
14761
  this.inSharedItems = true;
14699
- if (attributes.containsNumber === "1" || attributes.containsInteger === "1") {
14700
- if (this.model) {
14701
- this.model.containsNumber = attributes.containsNumber === "1";
14702
- this.model.containsInteger = attributes.containsInteger === "1";
14703
- if (attributes.minValue !== void 0) this.model.minValue = parseFloat(attributes.minValue);
14704
- if (attributes.maxValue !== void 0) this.model.maxValue = parseFloat(attributes.maxValue);
14705
- this.model.sharedItems = null;
14706
- }
14707
- } else if (this.model) {
14762
+ if (this.model) {
14763
+ this.model.containsNumber = attributes.containsNumber === "1";
14764
+ this.model.containsInteger = attributes.containsInteger === "1";
14765
+ if (attributes.minValue !== void 0) this.model.minValue = parseFloat(attributes.minValue);
14766
+ if (attributes.maxValue !== void 0) this.model.maxValue = parseFloat(attributes.maxValue);
14708
14767
  if (parseInt(attributes.count || "0", 10) > 0) this.model.sharedItems = [];
14768
+ else this.model.sharedItems = null;
14709
14769
  }
14710
14770
  break;
14711
14771
  case "s":
@@ -14796,8 +14856,6 @@ var ExcelTS = (function(exports) {
14796
14856
  ...PivotCacheDefinitionXform.PIVOT_CACHE_DEFINITION_ATTRIBUTES,
14797
14857
  "r:id": "rId1",
14798
14858
  refreshOnLoad: "1",
14799
- refreshedBy: "Author",
14800
- refreshedDate: "45125.026046874998",
14801
14859
  createdVersion: "8",
14802
14860
  refreshedVersion: "8",
14803
14861
  minRefreshableVersion: "3",
@@ -14824,8 +14882,6 @@ var ExcelTS = (function(exports) {
14824
14882
  ...PivotCacheDefinitionXform.PIVOT_CACHE_DEFINITION_ATTRIBUTES,
14825
14883
  "r:id": model.rId || "rId1",
14826
14884
  refreshOnLoad: model.refreshOnLoad || "1",
14827
- refreshedBy: model.refreshedBy || "Author",
14828
- refreshedDate: model.refreshedDate || "45125.026046874998",
14829
14885
  createdVersion: model.createdVersion || "8",
14830
14886
  refreshedVersion: model.refreshedVersion || "8",
14831
14887
  minRefreshableVersion: model.minRefreshableVersion || "3",
@@ -14855,8 +14911,6 @@ var ExcelTS = (function(exports) {
14855
14911
  cacheFields: [],
14856
14912
  rId: attributes["r:id"],
14857
14913
  refreshOnLoad: attributes.refreshOnLoad,
14858
- refreshedBy: attributes.refreshedBy,
14859
- refreshedDate: attributes.refreshedDate,
14860
14914
  createdVersion: attributes.createdVersion,
14861
14915
  refreshedVersion: attributes.refreshedVersion,
14862
14916
  minRefreshableVersion: attributes.minRefreshableVersion,
@@ -14911,10 +14965,7 @@ var ExcelTS = (function(exports) {
14911
14965
  static {
14912
14966
  this.PIVOT_CACHE_DEFINITION_ATTRIBUTES = {
14913
14967
  xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
14914
- "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
14915
- "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
14916
- "mc:Ignorable": "xr",
14917
- "xmlns:xr": "http://schemas.microsoft.com/office/spreadsheetml/2014/revision"
14968
+ "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
14918
14969
  };
14919
14970
  }
14920
14971
  };
@@ -14967,18 +15018,16 @@ var ExcelTS = (function(exports) {
14967
15018
  */
14968
15019
  renderNew(xmlStream, model) {
14969
15020
  const { rows, columns, values, cacheFields, cacheId, applyWidthHeightFormats } = model;
14970
- const uniqueUid = `{${crypto.randomUUID().toUpperCase()}}`;
14971
15021
  const rowItems = buildRowItems(rows, cacheFields);
14972
15022
  const colItems = buildColItems(columns, cacheFields, values.length);
14973
15023
  const rowFieldItemCount = rows.length > 0 ? cacheFields[rows[0]]?.sharedItems?.length || 0 : 0;
14974
15024
  const colFieldItemCount = columns.length > 0 ? cacheFields[columns[0]]?.sharedItems?.length || 0 : 0;
14975
- const endRow = 3 + rowFieldItemCount + 1;
15025
+ const endRow = 4 + rowFieldItemCount + 1;
14976
15026
  const endCol = 1 + colFieldItemCount + 1;
14977
15027
  const locationRef = `A3:${String.fromCharCode(64 + endCol)}${endRow}`;
14978
15028
  xmlStream.openXml(XmlStream.StdDocAttributes);
14979
15029
  xmlStream.openNode(this.tag, {
14980
15030
  ...PivotTableXform.PIVOT_TABLE_ATTRIBUTES,
14981
- "xr:uid": uniqueUid,
14982
15031
  name: "PivotTable2",
14983
15032
  cacheId,
14984
15033
  applyNumberFormats: "0",
@@ -15053,11 +15102,9 @@ var ExcelTS = (function(exports) {
15053
15102
  * Render loaded pivot table (preserving original structure)
15054
15103
  */
15055
15104
  renderLoaded(xmlStream, model) {
15056
- const uniqueUid = model.uid || `{${crypto.randomUUID().toUpperCase()}}`;
15057
15105
  xmlStream.openXml(XmlStream.StdDocAttributes);
15058
15106
  xmlStream.openNode(this.tag, {
15059
15107
  ...PivotTableXform.PIVOT_TABLE_ATTRIBUTES,
15060
- "xr:uid": uniqueUid,
15061
15108
  name: model.name || "PivotTable1",
15062
15109
  cacheId: model.cacheId,
15063
15110
  applyNumberFormats: model.applyNumberFormats || "0",
@@ -15306,19 +15353,15 @@ var ExcelTS = (function(exports) {
15306
15353
  }
15307
15354
  reconcile(_model, _options) {}
15308
15355
  static {
15309
- this.PIVOT_TABLE_ATTRIBUTES = {
15310
- xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
15311
- "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
15312
- "mc:Ignorable": "xr",
15313
- "xmlns:xr": "http://schemas.microsoft.com/office/spreadsheetml/2014/revision"
15314
- };
15356
+ this.PIVOT_TABLE_ATTRIBUTES = { xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main" };
15315
15357
  }
15316
15358
  };
15317
15359
  /**
15318
15360
  * Build rowItems XML - one item for each unique value in row fields, plus grand total.
15319
15361
  * Each <i> represents a row in the pivot table.
15320
- * - Regular items: <i><x v="index"/></i> where index is the position in sharedItems
15362
+ * - Regular items: <i><x/></i> for index 0, <i><x v="index"/></i> for index > 0
15321
15363
  * - Grand total: <i t="grand"><x/></i>
15364
+ * Note: When v=0, the v attribute should be omitted (Excel convention)
15322
15365
  */
15323
15366
  function buildRowItems(rows, cacheFields) {
15324
15367
  if (rows.length === 0) return {
@@ -15327,7 +15370,8 @@ var ExcelTS = (function(exports) {
15327
15370
  };
15328
15371
  const itemCount = (cacheFields[rows[0]]?.sharedItems || []).length;
15329
15372
  const items = [];
15330
- for (let i = 0; i < itemCount; i++) items.push(`<i><x v="${i}" /></i>`);
15373
+ for (let i = 0; i < itemCount; i++) if (i === 0) items.push("<i><x /></i>");
15374
+ else items.push(`<i><x v="${i}" /></i>`);
15331
15375
  items.push("<i t=\"grand\"><x /></i>");
15332
15376
  return {
15333
15377
  count: items.length,
@@ -15337,12 +15381,14 @@ var ExcelTS = (function(exports) {
15337
15381
  /**
15338
15382
  * Build colItems XML - one item for each unique value in column fields, plus grand total.
15339
15383
  * When there are multiple data fields (values), each column value may have sub-columns.
15384
+ * Note: When v=0, the v attribute should be omitted (Excel convention)
15340
15385
  */
15341
15386
  function buildColItems(columns, cacheFields, valueCount) {
15342
15387
  if (columns.length === 0) {
15343
15388
  if (valueCount > 1) {
15344
15389
  const items$1 = [];
15345
- for (let i = 0; i < valueCount; i++) items$1.push(`<i><x v="${i}" /></i>`);
15390
+ for (let i = 0; i < valueCount; i++) if (i === 0) items$1.push("<i><x /></i>");
15391
+ else items$1.push(`<i><x v="${i}" /></i>`);
15346
15392
  items$1.push("<i t=\"grand\"><x /></i>");
15347
15393
  return {
15348
15394
  count: items$1.length,
@@ -15356,7 +15402,8 @@ var ExcelTS = (function(exports) {
15356
15402
  }
15357
15403
  const itemCount = (cacheFields[columns[0]]?.sharedItems || []).length;
15358
15404
  const items = [];
15359
- for (let i = 0; i < itemCount; i++) items.push(`<i><x v="${i}" /></i>`);
15405
+ for (let i = 0; i < itemCount; i++) if (i === 0) items.push("<i><x /></i>");
15406
+ else items.push(`<i><x v="${i}" /></i>`);
15360
15407
  items.push("<i t=\"grand\"><x /></i>");
15361
15408
  return {
15362
15409
  count: items.length,
@@ -15382,16 +15429,17 @@ var ExcelTS = (function(exports) {
15382
15429
  const colSet = new Set(pivotTable.columns);
15383
15430
  const valueSet = new Set(pivotTable.values);
15384
15431
  return pivotTable.cacheFields.map((cacheField, fieldIndex) => {
15385
- return renderPivotField(rowSet.has(fieldIndex) ? "row" : colSet.has(fieldIndex) ? "column" : valueSet.has(fieldIndex) ? "value" : null, cacheField.sharedItems);
15432
+ return renderPivotField(rowSet.has(fieldIndex), colSet.has(fieldIndex), valueSet.has(fieldIndex), cacheField.sharedItems);
15386
15433
  }).join("");
15387
15434
  }
15388
- function renderPivotField(fieldType, sharedItems) {
15389
- const defaultAttributes = "compact=\"0\" outline=\"0\" showAll=\"0\" defaultSubtotal=\"0\"";
15390
- if (fieldType === "row" || fieldType === "column") {
15391
- const axis = fieldType === "row" ? "axisRow" : "axisCol";
15435
+ function renderPivotField(isRow, isCol, isValue, sharedItems) {
15436
+ if (isRow || isCol) {
15437
+ const axis = isRow ? "axisRow" : "axisCol";
15438
+ let axisAttributes = "compact=\"0\" outline=\"0\" showAll=\"0\"";
15439
+ if (isValue) axisAttributes = `dataField="1" ${axisAttributes}`;
15392
15440
  const itemsXml = [...sharedItems.map((_item, index) => `<item x="${index}" />`), "<item t=\"default\" />"].join("\n ");
15393
15441
  return `
15394
- <pivotField axis="${axis}" ${defaultAttributes}>
15442
+ <pivotField axis="${axis}" ${axisAttributes}>
15395
15443
  <items count="${sharedItems.length + 1}">
15396
15444
  ${itemsXml}
15397
15445
  </items>
@@ -15400,8 +15448,8 @@ var ExcelTS = (function(exports) {
15400
15448
  }
15401
15449
  return `
15402
15450
  <pivotField
15403
- ${fieldType === "value" ? "dataField=\"1\"" : ""}
15404
- ${defaultAttributes}
15451
+ ${isValue ? "dataField=\"1\"" : ""}
15452
+ compact="0" outline="0" showAll="0" defaultSubtotal="0"
15405
15453
  />
15406
15454
  `;
15407
15455
  }