@cj-tech-master/excelts 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @cj-tech-master/excelts v2.0.0
2
+ * @cj-tech-master/excelts v2.0.1
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
@@ -14787,6 +14787,7 @@ var PivotCacheDefinitionXform = class PivotCacheDefinitionXform extends BaseXfor
14787
14787
  */
14788
14788
  renderNew(xmlStream, model) {
14789
14789
  const { source, cacheFields } = model;
14790
+ const recordCount = source.getSheetValues().slice(2).length;
14790
14791
  xmlStream.openXml(XmlStream.StdDocAttributes);
14791
14792
  xmlStream.openNode(this.tag, {
14792
14793
  ...PivotCacheDefinitionXform.PIVOT_CACHE_DEFINITION_ATTRIBUTES,
@@ -14797,7 +14798,7 @@ var PivotCacheDefinitionXform = class PivotCacheDefinitionXform extends BaseXfor
14797
14798
  createdVersion: "8",
14798
14799
  refreshedVersion: "8",
14799
14800
  minRefreshableVersion: "3",
14800
- recordCount: cacheFields.length + 1
14801
+ recordCount
14801
14802
  });
14802
14803
  xmlStream.openNode("cacheSource", { type: "worksheet" });
14803
14804
  xmlStream.leafNode("worksheetSource", {
@@ -14964,6 +14965,13 @@ var PivotTableXform = class PivotTableXform extends BaseXform {
14964
14965
  renderNew(xmlStream, model) {
14965
14966
  const { rows, columns, values, cacheFields, cacheId, applyWidthHeightFormats } = model;
14966
14967
  const uniqueUid = `{${crypto.randomUUID().toUpperCase()}}`;
14968
+ const rowItems = buildRowItems(rows, cacheFields);
14969
+ const colItems = buildColItems(columns, cacheFields, values.length);
14970
+ const rowFieldItemCount = rows.length > 0 ? cacheFields[rows[0]]?.sharedItems?.length || 0 : 0;
14971
+ const colFieldItemCount = columns.length > 0 ? cacheFields[columns[0]]?.sharedItems?.length || 0 : 0;
14972
+ const endRow = 3 + rowFieldItemCount + 1;
14973
+ const endCol = 1 + colFieldItemCount + 1;
14974
+ const locationRef = `A3:${String.fromCharCode(64 + endCol)}${endRow}`;
14967
14975
  xmlStream.openXml(XmlStream.StdDocAttributes);
14968
14976
  xmlStream.openNode(this.tag, {
14969
14977
  ...PivotTableXform.PIVOT_TABLE_ATTRIBUTES,
@@ -14988,21 +14996,21 @@ var PivotTableXform = class PivotTableXform extends BaseXform {
14988
14996
  multipleFieldFilters: "0"
14989
14997
  });
14990
14998
  xmlStream.writeXml(`
14991
- <location ref="A3:E15" firstHeaderRow="1" firstDataRow="2" firstDataCol="1" />
14999
+ <location ref="${locationRef}" firstHeaderRow="1" firstDataRow="2" firstDataCol="1" />
14992
15000
  <pivotFields count="${cacheFields.length}">
14993
15001
  ${renderPivotFields(model)}
14994
15002
  </pivotFields>
14995
15003
  <rowFields count="${rows.length}">
14996
15004
  ${rows.map((rowIndex) => `<field x="${rowIndex}" />`).join("\n ")}
14997
15005
  </rowFields>
14998
- <rowItems count="1">
14999
- <i t="grand"><x /></i>
15006
+ <rowItems count="${rowItems.count}">
15007
+ ${rowItems.xml}
15000
15008
  </rowItems>
15001
15009
  <colFields count="${columns.length === 0 ? 1 : columns.length}">
15002
15010
  ${columns.length === 0 ? "<field x=\"-2\" />" : columns.map((columnIndex) => `<field x="${columnIndex}" />`).join("\n ")}
15003
15011
  </colFields>
15004
- <colItems count="1">
15005
- <i t="grand"><x /></i>
15012
+ <colItems count="${colItems.count}">
15013
+ ${colItems.xml}
15006
15014
  </colItems>
15007
15015
  <dataFields count="${values.length}">
15008
15016
  ${buildDataFields(cacheFields, values, model.metric)}
@@ -15304,6 +15312,55 @@ var PivotTableXform = class PivotTableXform extends BaseXform {
15304
15312
  }
15305
15313
  };
15306
15314
  /**
15315
+ * Build rowItems XML - one item for each unique value in row fields, plus grand total.
15316
+ * Each <i> represents a row in the pivot table.
15317
+ * - Regular items: <i><x v="index"/></i> where index is the position in sharedItems
15318
+ * - Grand total: <i t="grand"><x/></i>
15319
+ */
15320
+ function buildRowItems(rows, cacheFields) {
15321
+ if (rows.length === 0) return {
15322
+ count: 1,
15323
+ xml: "<i t=\"grand\"><x /></i>"
15324
+ };
15325
+ const itemCount = (cacheFields[rows[0]]?.sharedItems || []).length;
15326
+ const items = [];
15327
+ for (let i = 0; i < itemCount; i++) items.push(`<i><x v="${i}" /></i>`);
15328
+ items.push("<i t=\"grand\"><x /></i>");
15329
+ return {
15330
+ count: items.length,
15331
+ xml: items.join("\n ")
15332
+ };
15333
+ }
15334
+ /**
15335
+ * Build colItems XML - one item for each unique value in column fields, plus grand total.
15336
+ * When there are multiple data fields (values), each column value may have sub-columns.
15337
+ */
15338
+ function buildColItems(columns, cacheFields, valueCount) {
15339
+ if (columns.length === 0) {
15340
+ if (valueCount > 1) {
15341
+ const items$1 = [];
15342
+ for (let i = 0; i < valueCount; i++) items$1.push(`<i><x v="${i}" /></i>`);
15343
+ items$1.push("<i t=\"grand\"><x /></i>");
15344
+ return {
15345
+ count: items$1.length,
15346
+ xml: items$1.join("\n ")
15347
+ };
15348
+ }
15349
+ return {
15350
+ count: 1,
15351
+ xml: "<i t=\"grand\"><x /></i>"
15352
+ };
15353
+ }
15354
+ const itemCount = (cacheFields[columns[0]]?.sharedItems || []).length;
15355
+ const items = [];
15356
+ for (let i = 0; i < itemCount; i++) items.push(`<i><x v="${i}" /></i>`);
15357
+ items.push("<i t=\"grand\"><x /></i>");
15358
+ return {
15359
+ count: items.length,
15360
+ xml: items.join("\n ")
15361
+ };
15362
+ }
15363
+ /**
15307
15364
  * Build dataField XML elements for all values in the pivot table.
15308
15365
  * Supports multiple values when columns is empty.
15309
15366
  */
@@ -15327,13 +15384,17 @@ function renderPivotFields(pivotTable) {
15327
15384
  }
15328
15385
  function renderPivotField(fieldType, sharedItems) {
15329
15386
  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}>
15387
+ if (fieldType === "row" || fieldType === "column") {
15388
+ const axis = fieldType === "row" ? "axisRow" : "axisCol";
15389
+ const itemsXml = [...sharedItems.map((_item, index) => `<item x="${index}" />`), "<item t=\"default\" />"].join("\n ");
15390
+ return `
15391
+ <pivotField axis="${axis}" ${defaultAttributes}>
15332
15392
  <items count="${sharedItems.length + 1}">
15333
- ${sharedItems.map((_item, index) => `<item x="${index}" />`).join("\n ")}
15393
+ ${itemsXml}
15334
15394
  </items>
15335
15395
  </pivotField>
15336
15396
  `;
15397
+ }
15337
15398
  return `
15338
15399
  <pivotField
15339
15400
  ${fieldType === "value" ? "dataField=\"1\"" : ""}
@@ -16782,13 +16843,6 @@ const AUTO_DETECT = [
16782
16843
  [25, [parseISOOffset]],
16783
16844
  [29, [parseISOMsOffset]]
16784
16845
  ];
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
16846
  /**
16793
16847
  * Optimized date parser for batch processing
16794
16848
  *
@@ -16842,6 +16896,13 @@ var DateParser = class DateParser {
16842
16896
  return out;
16843
16897
  }
16844
16898
  };
16899
+ function tzOffset(d) {
16900
+ const off = -d.getTimezoneOffset();
16901
+ const sign = off >= 0 ? "+" : "-";
16902
+ const h = Math.abs(off) / 60 | 0;
16903
+ const m = Math.abs(off) % 60;
16904
+ return `${sign}${PAD2[h]}:${PAD2[m]}`;
16905
+ }
16845
16906
  /**
16846
16907
  * Optimized date formatter for batch processing
16847
16908
  *