@cj-tech-master/excelts 3.0.0 → 3.0.1-canary.20251230172852.9dca08f

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 v3.0.0
2
+ * @cj-tech-master/excelts v3.0.1-canary.20251230172852.9dca08f
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
@@ -1675,6 +1675,27 @@ var ExcelTS = (function(exports) {
1675
1675
  });
1676
1676
  }
1677
1677
  /**
1678
+ * Get row values as a 0-based sparse array (column 1 => index 0).
1679
+ *
1680
+ * This is useful when you want to compare/stringify values without the
1681
+ * leading separator produced by the 1-based sparse array returned by `values`.
1682
+ */
1683
+ getValues() {
1684
+ const values = [];
1685
+ this._cells.forEach((cell) => {
1686
+ if (cell && cell.type !== Enums.ValueType.Null) values[cell.col - 1] = cell.value;
1687
+ });
1688
+ return values;
1689
+ }
1690
+ /**
1691
+ * Convenience stringification for row values.
1692
+ *
1693
+ * Equivalent to `row.getValues().join(separator)`.
1694
+ */
1695
+ valuesToString(separator = ",") {
1696
+ return this.getValues().join(separator);
1697
+ }
1698
+ /**
1678
1699
  * Returns true if the row includes at least one cell with a value
1679
1700
  */
1680
1701
  get hasValues() {
@@ -3002,7 +3023,7 @@ var ExcelTS = (function(exports) {
3002
3023
  validate(worksheet, model, source);
3003
3024
  const { rows, values } = model;
3004
3025
  const columns = model.columns ?? [];
3005
- const cacheFields = makeCacheFields(source, [...rows, ...columns]);
3026
+ const cacheFields = makeCacheFields(source, [...rows, ...columns], values);
3006
3027
  const nameToIndex = cacheFields.reduce((result, cacheField, index) => {
3007
3028
  result[cacheField.name] = index;
3008
3029
  return result;
@@ -3037,9 +3058,10 @@ var ExcelTS = (function(exports) {
3037
3058
  if (model.values.length < 1) throw new Error("Must have at least one value.");
3038
3059
  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
3060
  }
3040
- function makeCacheFields(source, fieldNamesWithSharedItems) {
3061
+ function makeCacheFields(source, fieldNamesWithSharedItems, valueFieldNames) {
3041
3062
  const names = source.getRow(1).values;
3042
3063
  const sharedItemsFields = new Set(fieldNamesWithSharedItems);
3064
+ const valueFields = new Set(valueFieldNames);
3043
3065
  const aggregate = (columnIndex) => {
3044
3066
  const columnValues = source.getColumn(columnIndex).values;
3045
3067
  const uniqueValues = /* @__PURE__ */ new Set();
@@ -3074,7 +3096,7 @@ var ExcelTS = (function(exports) {
3074
3096
  name,
3075
3097
  sharedItems: aggregate(columnIndex)
3076
3098
  });
3077
- else {
3099
+ else if (valueFields.has(name)) {
3078
3100
  const minMax = getMinMax(columnIndex);
3079
3101
  result.push({
3080
3102
  name,
@@ -3082,7 +3104,10 @@ var ExcelTS = (function(exports) {
3082
3104
  minValue: minMax?.minValue,
3083
3105
  maxValue: minMax?.maxValue
3084
3106
  });
3085
- }
3107
+ } else result.push({
3108
+ name,
3109
+ sharedItems: null
3110
+ });
3086
3111
  }
3087
3112
  return result;
3088
3113
  }
@@ -14683,9 +14708,25 @@ var ExcelTS = (function(exports) {
14683
14708
  }
14684
14709
  render() {
14685
14710
  const escapedName = xmlEncode(this.name);
14686
- if (this.sharedItems === null) return `<cacheField name="${escapedName}" numFmtId="0">
14687
- <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1"${this.minValue !== void 0 && this.maxValue !== void 0 ? ` minValue="${this.minValue}" maxValue="${this.maxValue}"` : ""} />
14711
+ if (this.sharedItems === null) {
14712
+ if (this.minValue === void 0 || this.maxValue === void 0) return `<cacheField name="${escapedName}" numFmtId="0">
14713
+ <sharedItems />
14714
+ </cacheField>`;
14715
+ return `<cacheField name="${escapedName}" numFmtId="0">
14716
+ <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1" minValue="${this.minValue}" maxValue="${this.maxValue}" />
14688
14717
  </cacheField>`;
14718
+ }
14719
+ const allNumeric = this.sharedItems.length > 0 && this.sharedItems.every((item) => typeof item === "number" && Number.isFinite(item));
14720
+ const allInteger = allNumeric && this.sharedItems.every((item) => Number.isInteger(item));
14721
+ if (allNumeric) {
14722
+ const minValue = Math.min(...this.sharedItems);
14723
+ const maxValue = Math.max(...this.sharedItems);
14724
+ return `<cacheField name="${escapedName}" numFmtId="0">
14725
+ <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1"${allInteger ? " containsInteger=\"1\"" : ""} minValue="${minValue}" maxValue="${maxValue}" count="${this.sharedItems.length}">
14726
+ ${this.sharedItems.map((item) => `<n v="${item}" />`).join("")}
14727
+ </sharedItems>
14728
+ </cacheField>`;
14729
+ }
14689
14730
  return `<cacheField name="${escapedName}" numFmtId="0">
14690
14731
  <sharedItems count="${this.sharedItems.length}">
14691
14732
  ${this.sharedItems.map((item) => `<s v="${xmlEncode(String(item))}" />`).join("")}
@@ -14739,16 +14780,13 @@ var ExcelTS = (function(exports) {
14739
14780
  break;
14740
14781
  case "sharedItems":
14741
14782
  this.inSharedItems = true;
14742
- if (attributes.containsNumber === "1" || attributes.containsInteger === "1") {
14743
- if (this.model) {
14744
- this.model.containsNumber = attributes.containsNumber === "1";
14745
- this.model.containsInteger = attributes.containsInteger === "1";
14746
- if (attributes.minValue !== void 0) this.model.minValue = parseFloat(attributes.minValue);
14747
- if (attributes.maxValue !== void 0) this.model.maxValue = parseFloat(attributes.maxValue);
14748
- this.model.sharedItems = null;
14749
- }
14750
- } else if (this.model) {
14783
+ if (this.model) {
14784
+ this.model.containsNumber = attributes.containsNumber === "1";
14785
+ this.model.containsInteger = attributes.containsInteger === "1";
14786
+ if (attributes.minValue !== void 0) this.model.minValue = parseFloat(attributes.minValue);
14787
+ if (attributes.maxValue !== void 0) this.model.maxValue = parseFloat(attributes.maxValue);
14751
14788
  if (parseInt(attributes.count || "0", 10) > 0) this.model.sharedItems = [];
14789
+ else this.model.sharedItems = null;
14752
14790
  }
14753
14791
  break;
14754
14792
  case "s":
@@ -15412,13 +15450,14 @@ var ExcelTS = (function(exports) {
15412
15450
  const colSet = new Set(pivotTable.columns);
15413
15451
  const valueSet = new Set(pivotTable.values);
15414
15452
  return pivotTable.cacheFields.map((cacheField, fieldIndex) => {
15415
- return renderPivotField(rowSet.has(fieldIndex) ? "row" : colSet.has(fieldIndex) ? "column" : valueSet.has(fieldIndex) ? "value" : null, cacheField.sharedItems);
15453
+ return renderPivotField(rowSet.has(fieldIndex), colSet.has(fieldIndex), valueSet.has(fieldIndex), cacheField.sharedItems);
15416
15454
  }).join("");
15417
15455
  }
15418
- function renderPivotField(fieldType, sharedItems) {
15419
- if (fieldType === "row" || fieldType === "column") {
15420
- const axis = fieldType === "row" ? "axisRow" : "axisCol";
15421
- const axisAttributes = "compact=\"0\" outline=\"0\" showAll=\"0\"";
15456
+ function renderPivotField(isRow, isCol, isValue, sharedItems) {
15457
+ if (isRow || isCol) {
15458
+ const axis = isRow ? "axisRow" : "axisCol";
15459
+ let axisAttributes = "compact=\"0\" outline=\"0\" showAll=\"0\"";
15460
+ if (isValue) axisAttributes = `dataField="1" ${axisAttributes}`;
15422
15461
  const itemsXml = [...sharedItems.map((_item, index) => `<item x="${index}" />`), "<item t=\"default\" />"].join("\n ");
15423
15462
  return `
15424
15463
  <pivotField axis="${axis}" ${axisAttributes}>
@@ -15430,7 +15469,7 @@ var ExcelTS = (function(exports) {
15430
15469
  }
15431
15470
  return `
15432
15471
  <pivotField
15433
- ${fieldType === "value" ? "dataField=\"1\"" : ""}
15472
+ ${isValue ? "dataField=\"1\"" : ""}
15434
15473
  compact="0" outline="0" showAll="0" defaultSubtotal="0"
15435
15474
  />
15436
15475
  `;