@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.
package/README.md CHANGED
@@ -23,8 +23,9 @@ ExcelTS is a modernized fork of [ExcelJS](https://github.com/exceljs/exceljs) wi
23
23
 
24
24
  ## Installation
25
25
 
26
- ````bash
26
+ ```bash
27
27
  npm install @cj-tech-master/excelts
28
+ ```
28
29
 
29
30
  ## Quick Start
30
31
 
@@ -43,7 +44,7 @@ sheet.addRow(["Jane Smith", 25, "jane@example.com"]);
43
44
 
44
45
  // Save to file
45
46
  await workbook.xlsx.writeFile("output.xlsx");
46
- ````
47
+ ```
47
48
 
48
49
  ### Reading a Workbook
49
50
 
@@ -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
@@ -1672,6 +1672,27 @@ var Row = class {
1672
1672
  });
1673
1673
  }
1674
1674
  /**
1675
+ * Get row values as a 0-based sparse array (column 1 => index 0).
1676
+ *
1677
+ * This is useful when you want to compare/stringify values without the
1678
+ * leading separator produced by the 1-based sparse array returned by `values`.
1679
+ */
1680
+ getValues() {
1681
+ const values = [];
1682
+ this._cells.forEach((cell) => {
1683
+ if (cell && cell.type !== Enums.ValueType.Null) values[cell.col - 1] = cell.value;
1684
+ });
1685
+ return values;
1686
+ }
1687
+ /**
1688
+ * Convenience stringification for row values.
1689
+ *
1690
+ * Equivalent to `row.getValues().join(separator)`.
1691
+ */
1692
+ valuesToString(separator = ",") {
1693
+ return this.getValues().join(separator);
1694
+ }
1695
+ /**
1675
1696
  * Returns true if the row includes at least one cell with a value
1676
1697
  */
1677
1698
  get hasValues() {
@@ -2999,7 +3020,7 @@ function makePivotTable(worksheet, model) {
2999
3020
  validate(worksheet, model, source);
3000
3021
  const { rows, values } = model;
3001
3022
  const columns = model.columns ?? [];
3002
- const cacheFields = makeCacheFields(source, [...rows, ...columns]);
3023
+ const cacheFields = makeCacheFields(source, [...rows, ...columns], values);
3003
3024
  const nameToIndex = cacheFields.reduce((result, cacheField, index) => {
3004
3025
  result[cacheField.name] = index;
3005
3026
  return result;
@@ -3034,9 +3055,10 @@ function validate(_worksheet, model, source) {
3034
3055
  if (model.values.length < 1) throw new Error("Must have at least one value.");
3035
3056
  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.");
3036
3057
  }
3037
- function makeCacheFields(source, fieldNamesWithSharedItems) {
3058
+ function makeCacheFields(source, fieldNamesWithSharedItems, valueFieldNames) {
3038
3059
  const names = source.getRow(1).values;
3039
3060
  const sharedItemsFields = new Set(fieldNamesWithSharedItems);
3061
+ const valueFields = new Set(valueFieldNames);
3040
3062
  const aggregate = (columnIndex) => {
3041
3063
  const columnValues = source.getColumn(columnIndex).values;
3042
3064
  const uniqueValues = /* @__PURE__ */ new Set();
@@ -3071,7 +3093,7 @@ function makeCacheFields(source, fieldNamesWithSharedItems) {
3071
3093
  name,
3072
3094
  sharedItems: aggregate(columnIndex)
3073
3095
  });
3074
- else {
3096
+ else if (valueFields.has(name)) {
3075
3097
  const minMax = getMinMax(columnIndex);
3076
3098
  result.push({
3077
3099
  name,
@@ -3079,7 +3101,10 @@ function makeCacheFields(source, fieldNamesWithSharedItems) {
3079
3101
  minValue: minMax?.minValue,
3080
3102
  maxValue: minMax?.maxValue
3081
3103
  });
3082
- }
3104
+ } else result.push({
3105
+ name,
3106
+ sharedItems: null
3107
+ });
3083
3108
  }
3084
3109
  return result;
3085
3110
  }
@@ -14680,9 +14705,25 @@ var CacheField = class {
14680
14705
  }
14681
14706
  render() {
14682
14707
  const escapedName = xmlEncode(this.name);
14683
- if (this.sharedItems === null) return `<cacheField name="${escapedName}" numFmtId="0">
14684
- <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1"${this.minValue !== void 0 && this.maxValue !== void 0 ? ` minValue="${this.minValue}" maxValue="${this.maxValue}"` : ""} />
14708
+ if (this.sharedItems === null) {
14709
+ if (this.minValue === void 0 || this.maxValue === void 0) return `<cacheField name="${escapedName}" numFmtId="0">
14710
+ <sharedItems />
14711
+ </cacheField>`;
14712
+ return `<cacheField name="${escapedName}" numFmtId="0">
14713
+ <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1" minValue="${this.minValue}" maxValue="${this.maxValue}" />
14685
14714
  </cacheField>`;
14715
+ }
14716
+ const allNumeric = this.sharedItems.length > 0 && this.sharedItems.every((item) => typeof item === "number" && Number.isFinite(item));
14717
+ const allInteger = allNumeric && this.sharedItems.every((item) => Number.isInteger(item));
14718
+ if (allNumeric) {
14719
+ const minValue = Math.min(...this.sharedItems);
14720
+ const maxValue = Math.max(...this.sharedItems);
14721
+ return `<cacheField name="${escapedName}" numFmtId="0">
14722
+ <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1"${allInteger ? " containsInteger=\"1\"" : ""} minValue="${minValue}" maxValue="${maxValue}" count="${this.sharedItems.length}">
14723
+ ${this.sharedItems.map((item) => `<n v="${item}" />`).join("")}
14724
+ </sharedItems>
14725
+ </cacheField>`;
14726
+ }
14686
14727
  return `<cacheField name="${escapedName}" numFmtId="0">
14687
14728
  <sharedItems count="${this.sharedItems.length}">
14688
14729
  ${this.sharedItems.map((item) => `<s v="${xmlEncode(String(item))}" />`).join("")}
@@ -14736,16 +14777,13 @@ var CacheFieldXform = class extends BaseXform {
14736
14777
  break;
14737
14778
  case "sharedItems":
14738
14779
  this.inSharedItems = true;
14739
- if (attributes.containsNumber === "1" || attributes.containsInteger === "1") {
14740
- if (this.model) {
14741
- this.model.containsNumber = attributes.containsNumber === "1";
14742
- this.model.containsInteger = attributes.containsInteger === "1";
14743
- if (attributes.minValue !== void 0) this.model.minValue = parseFloat(attributes.minValue);
14744
- if (attributes.maxValue !== void 0) this.model.maxValue = parseFloat(attributes.maxValue);
14745
- this.model.sharedItems = null;
14746
- }
14747
- } else if (this.model) {
14780
+ if (this.model) {
14781
+ this.model.containsNumber = attributes.containsNumber === "1";
14782
+ this.model.containsInteger = attributes.containsInteger === "1";
14783
+ if (attributes.minValue !== void 0) this.model.minValue = parseFloat(attributes.minValue);
14784
+ if (attributes.maxValue !== void 0) this.model.maxValue = parseFloat(attributes.maxValue);
14748
14785
  if (parseInt(attributes.count || "0", 10) > 0) this.model.sharedItems = [];
14786
+ else this.model.sharedItems = null;
14749
14787
  }
14750
14788
  break;
14751
14789
  case "s":
@@ -15409,13 +15447,14 @@ function renderPivotFields(pivotTable) {
15409
15447
  const colSet = new Set(pivotTable.columns);
15410
15448
  const valueSet = new Set(pivotTable.values);
15411
15449
  return pivotTable.cacheFields.map((cacheField, fieldIndex) => {
15412
- return renderPivotField(rowSet.has(fieldIndex) ? "row" : colSet.has(fieldIndex) ? "column" : valueSet.has(fieldIndex) ? "value" : null, cacheField.sharedItems);
15450
+ return renderPivotField(rowSet.has(fieldIndex), colSet.has(fieldIndex), valueSet.has(fieldIndex), cacheField.sharedItems);
15413
15451
  }).join("");
15414
15452
  }
15415
- function renderPivotField(fieldType, sharedItems) {
15416
- if (fieldType === "row" || fieldType === "column") {
15417
- const axis = fieldType === "row" ? "axisRow" : "axisCol";
15418
- const axisAttributes = "compact=\"0\" outline=\"0\" showAll=\"0\"";
15453
+ function renderPivotField(isRow, isCol, isValue, sharedItems) {
15454
+ if (isRow || isCol) {
15455
+ const axis = isRow ? "axisRow" : "axisCol";
15456
+ let axisAttributes = "compact=\"0\" outline=\"0\" showAll=\"0\"";
15457
+ if (isValue) axisAttributes = `dataField="1" ${axisAttributes}`;
15419
15458
  const itemsXml = [...sharedItems.map((_item, index) => `<item x="${index}" />`), "<item t=\"default\" />"].join("\n ");
15420
15459
  return `
15421
15460
  <pivotField axis="${axis}" ${axisAttributes}>
@@ -15427,7 +15466,7 @@ function renderPivotField(fieldType, sharedItems) {
15427
15466
  }
15428
15467
  return `
15429
15468
  <pivotField
15430
- ${fieldType === "value" ? "dataField=\"1\"" : ""}
15469
+ ${isValue ? "dataField=\"1\"" : ""}
15431
15470
  compact="0" outline="0" showAll="0" defaultSubtotal="0"
15432
15471
  />
15433
15472
  `;