@cj-tech-master/excelts 1.6.3-canary.20251224193747.e89b618 → 1.6.3-canary.20251226035947.ef0b4f2

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 (68) hide show
  1. package/README.md +5 -4
  2. package/README_zh.md +5 -4
  3. package/dist/browser/excelts.esm.js +2447 -3094
  4. package/dist/browser/excelts.esm.js.map +1 -1
  5. package/dist/browser/excelts.esm.min.js +23 -25
  6. package/dist/browser/excelts.iife.js +2448 -3095
  7. package/dist/browser/excelts.iife.js.map +1 -1
  8. package/dist/browser/excelts.iife.min.js +23 -25
  9. package/dist/cjs/csv/csv-core.js +2 -2
  10. package/dist/cjs/csv/csv-stream.js +1 -1
  11. package/dist/cjs/csv/csv.base.js +10 -27
  12. package/dist/cjs/csv/csv.js +4 -12
  13. package/dist/cjs/doc/column.js +21 -0
  14. package/dist/cjs/doc/worksheet.js +4 -0
  15. package/dist/cjs/stream/xlsx/workbook-writer.js +4 -4
  16. package/dist/cjs/stream/xlsx/worksheet-writer.js +8 -1
  17. package/dist/cjs/utils/datetime.js +648 -0
  18. package/dist/cjs/utils/parse-sax.js +1190 -12
  19. package/dist/cjs/utils/unzip/zip-parser.js +11 -0
  20. package/dist/cjs/utils/zip/compress.base.js +3 -0
  21. package/dist/cjs/utils/zip/compress.browser.js +74 -30
  22. package/dist/cjs/utils/zip/deflate-fallback.js +575 -0
  23. package/dist/cjs/utils/zip/streaming-zip.js +264 -0
  24. package/dist/cjs/xlsx/xform/sheet/col-breaks-xform.js +38 -0
  25. package/dist/cjs/xlsx/xform/sheet/page-breaks-xform.js +13 -1
  26. package/dist/cjs/xlsx/xform/sheet/row-breaks-xform.js +11 -13
  27. package/dist/cjs/xlsx/xform/sheet/worksheet-xform.js +7 -2
  28. package/dist/cjs/xlsx/xlsx.browser.js +10 -53
  29. package/dist/cjs/xlsx/xlsx.js +27 -59
  30. package/dist/esm/csv/csv-core.js +2 -2
  31. package/dist/esm/csv/csv-stream.js +1 -1
  32. package/dist/esm/csv/csv.base.js +10 -24
  33. package/dist/esm/csv/csv.js +4 -12
  34. package/dist/esm/doc/column.js +21 -0
  35. package/dist/esm/doc/worksheet.js +4 -0
  36. package/dist/esm/stream/xlsx/workbook-writer.js +1 -1
  37. package/dist/esm/stream/xlsx/worksheet-writer.js +8 -1
  38. package/dist/esm/utils/datetime.js +639 -0
  39. package/dist/esm/utils/parse-sax.js +1188 -12
  40. package/dist/esm/utils/unzip/zip-parser.js +11 -0
  41. package/dist/esm/utils/zip/compress.base.js +3 -0
  42. package/dist/esm/utils/zip/compress.browser.js +76 -31
  43. package/dist/esm/utils/zip/deflate-fallback.js +570 -0
  44. package/dist/esm/utils/zip/streaming-zip.js +259 -0
  45. package/dist/esm/xlsx/xform/sheet/col-breaks-xform.js +35 -0
  46. package/dist/esm/xlsx/xform/sheet/page-breaks-xform.js +13 -1
  47. package/dist/esm/xlsx/xform/sheet/row-breaks-xform.js +11 -13
  48. package/dist/esm/xlsx/xform/sheet/worksheet-xform.js +7 -2
  49. package/dist/esm/xlsx/xlsx.browser.js +10 -53
  50. package/dist/esm/xlsx/xlsx.js +27 -59
  51. package/dist/types/csv/csv-core.d.ts +6 -6
  52. package/dist/types/csv/csv.base.d.ts +4 -3
  53. package/dist/types/doc/column.d.ts +6 -0
  54. package/dist/types/doc/worksheet.d.ts +3 -1
  55. package/dist/types/stream/xlsx/workbook-writer.d.ts +1 -1
  56. package/dist/types/stream/xlsx/worksheet-writer.d.ts +3 -1
  57. package/dist/types/types.d.ts +6 -0
  58. package/dist/types/utils/datetime.d.ts +85 -0
  59. package/dist/types/utils/parse-sax.d.ts +108 -1
  60. package/dist/types/utils/unzip/zip-parser.d.ts +5 -0
  61. package/dist/types/utils/zip/compress.base.d.ts +3 -0
  62. package/dist/types/utils/zip/compress.browser.d.ts +27 -18
  63. package/dist/types/utils/zip/deflate-fallback.d.ts +39 -0
  64. package/dist/types/utils/zip/streaming-zip.d.ts +96 -0
  65. package/dist/types/xlsx/xform/sheet/col-breaks-xform.d.ts +16 -0
  66. package/dist/types/xlsx/xform/sheet/page-breaks-xform.d.ts +4 -0
  67. package/dist/types/xlsx/xform/sheet/row-breaks-xform.d.ts +4 -0
  68. package/package.json +7 -28
@@ -2,15 +2,10 @@
2
2
  * CSV Base class - Shared functionality for Node.js and Browser
3
3
  *
4
4
  * Uses native CSV parser (RFC 4180 compliant) with zero external dependencies.
5
- * Date parsing uses dayjs for format flexibility.
5
+ * Date parsing uses native high-performance datetime utilities.
6
6
  */
7
- import dayjs from "dayjs";
8
- import customParseFormat from "dayjs/plugin/customParseFormat.js";
9
- import utc from "dayjs/plugin/utc.js";
7
+ import { DateParser, DateFormatter } from "../utils/datetime.js";
10
8
  import { parseCsv, formatCsv } from "./csv-core.js";
11
- // Initialize dayjs plugins
12
- dayjs.extend(customParseFormat);
13
- dayjs.extend(utc);
14
9
  // Special Excel values mapping
15
10
  const SpecialValues = {
16
11
  true: true,
@@ -27,6 +22,7 @@ const SpecialValues = {
27
22
  * Create the default value mapper for CSV parsing
28
23
  */
29
24
  export function createDefaultValueMapper(dateFormats) {
25
+ const dateParser = DateParser.create(dateFormats);
30
26
  return function mapValue(datum) {
31
27
  if (datum === "") {
32
28
  return null;
@@ -37,18 +33,9 @@ export function createDefaultValueMapper(dateFormats) {
37
33
  return datumNumber;
38
34
  }
39
35
  // Try to parse as date
40
- const dt = dateFormats.reduce((matchingDate, currentDateFormat) => {
41
- if (matchingDate) {
42
- return matchingDate;
43
- }
44
- const dayjsObj = dayjs(datum, currentDateFormat, true);
45
- if (dayjsObj.isValid()) {
46
- return dayjsObj;
47
- }
48
- return null;
49
- }, null);
50
- if (dt) {
51
- return new Date(dt.valueOf());
36
+ const date = dateParser.parse(datum);
37
+ if (date) {
38
+ return date;
52
39
  }
53
40
  // Check for special values
54
41
  const special = SpecialValues[datum];
@@ -62,6 +49,9 @@ export function createDefaultValueMapper(dateFormats) {
62
49
  * Create the default value mapper for CSV writing
63
50
  */
64
51
  export function createDefaultWriteMapper(dateFormat, dateUTC) {
52
+ const formatter = dateFormat
53
+ ? DateFormatter.create(dateFormat, { utc: dateUTC })
54
+ : DateFormatter.iso(dateUTC);
65
55
  return function mapValue(value) {
66
56
  if (value) {
67
57
  // Handle hyperlinks
@@ -74,10 +64,7 @@ export function createDefaultWriteMapper(dateFormat, dateUTC) {
74
64
  }
75
65
  // Handle dates
76
66
  if (value instanceof Date) {
77
- if (dateFormat) {
78
- return dateUTC ? dayjs.utc(value).format(dateFormat) : dayjs(value).format(dateFormat);
79
- }
80
- return dateUTC ? dayjs.utc(value).format() : dayjs(value).format();
67
+ return formatter.format(value);
81
68
  }
82
69
  // Handle errors
83
70
  if (value.error) {
@@ -99,7 +86,6 @@ export function parseCsvToWorksheet(content, workbook, options = {}) {
99
86
  const dateFormats = options.dateFormats || [
100
87
  "YYYY-MM-DD[T]HH:mm:ssZ",
101
88
  "YYYY-MM-DD[T]HH:mm:ss",
102
- "MM-DD-YYYY",
103
89
  "YYYY-MM-DD"
104
90
  ];
105
91
  const map = options.map || createDefaultValueMapper(dateFormats);
@@ -49,12 +49,8 @@ class CSV {
49
49
  */
50
50
  async read(stream, options) {
51
51
  const worksheet = this.workbook.addWorksheet(options?.sheetName);
52
- const dateFormats = options?.dateFormats || [
53
- "YYYY-MM-DD[T]HH:mm:ssZ",
54
- "YYYY-MM-DD[T]HH:mm:ss",
55
- "MM-DD-YYYY",
56
- "YYYY-MM-DD"
57
- ];
52
+ const dateFormats = options?.dateFormats ??
53
+ ["YYYY-MM-DD[T]HH:mm:ssZ", "YYYY-MM-DD[T]HH:mm:ss", "MM-DD-YYYY", "YYYY-MM-DD"];
58
54
  const map = options?.map || createDefaultValueMapper(dateFormats);
59
55
  const parser = new CsvParserStream(options?.parserOptions);
60
56
  return new Promise((resolve, reject) => {
@@ -199,12 +195,8 @@ class CSV {
199
195
  */
200
196
  createWriteStream(options) {
201
197
  const worksheet = this.workbook.addWorksheet(options?.sheetName);
202
- const dateFormats = options?.dateFormats || [
203
- "YYYY-MM-DD[T]HH:mm:ssZ",
204
- "YYYY-MM-DD[T]HH:mm:ss",
205
- "MM-DD-YYYY",
206
- "YYYY-MM-DD"
207
- ];
198
+ const dateFormats = options?.dateFormats ??
199
+ ["YYYY-MM-DD[T]HH:mm:ssZ", "YYYY-MM-DD[T]HH:mm:ss", "MM-DD-YYYY", "YYYY-MM-DD"];
208
200
  const map = options?.map || createDefaultValueMapper(dateFormats);
209
201
  const parser = new CsvParserStream(options?.parserOptions);
210
202
  parser.on("data", (row) => {
@@ -215,6 +215,27 @@ class Column {
215
215
  });
216
216
  }
217
217
  // =========================================================================
218
+ // Page Breaks
219
+ /**
220
+ * Add a page break after this column.
221
+ * @param top - Optional top row limit for the page break (1-indexed)
222
+ * @param bottom - Optional bottom row limit for the page break (1-indexed)
223
+ */
224
+ addPageBreak(top, bottom) {
225
+ const ws = this._worksheet;
226
+ const topRow = Math.max(0, (top || 0) - 1) || 0;
227
+ const bottomRow = Math.max(0, (bottom || 0) - 1) || 1048575;
228
+ const pb = {
229
+ id: this._number,
230
+ max: bottomRow,
231
+ man: 1
232
+ };
233
+ if (topRow) {
234
+ pb.min = topRow;
235
+ }
236
+ ws.colBreaks.push(pb);
237
+ }
238
+ // =========================================================================
218
239
  // styles
219
240
  get numFmt() {
220
241
  return this.style.numFmt;
@@ -36,6 +36,7 @@ class Worksheet {
36
36
  this._merges = {};
37
37
  // record of all row and column pageBreaks
38
38
  this.rowBreaks = [];
39
+ this.colBreaks = [];
39
40
  // for tabColor, default row height, outline levels, etc
40
41
  this.properties = Object.assign({}, {
41
42
  defaultRowHeight: 15,
@@ -850,6 +851,7 @@ class Worksheet {
850
851
  pageSetup: this.pageSetup,
851
852
  headerFooter: this.headerFooter,
852
853
  rowBreaks: this.rowBreaks,
854
+ colBreaks: this.colBreaks,
853
855
  views: this.views,
854
856
  autoFilter: this.autoFilter,
855
857
  media: this._media.map(medium => medium.model),
@@ -908,6 +910,8 @@ class Worksheet {
908
910
  this.properties = value.properties;
909
911
  this.pageSetup = value.pageSetup;
910
912
  this.headerFooter = value.headerFooter;
913
+ this.rowBreaks = value.rowBreaks || [];
914
+ this.colBreaks = value.colBreaks || [];
911
915
  this.views = value.views;
912
916
  this.autoFilter = value.autoFilter;
913
917
  this._media = value.media.map(medium => new Image(this, medium));
@@ -1,5 +1,5 @@
1
1
  import fs from "fs";
2
- import { Zip, ZipDeflate } from "fflate";
2
+ import { Zip, ZipDeflate } from "../../utils/zip/streaming-zip.js";
3
3
  import { StreamBuf } from "../../utils/stream-buf.js";
4
4
  import { RelType } from "../../xlsx/rel-type.js";
5
5
  import { StylesXform } from "../../xlsx/xform/style/styles-xform.js";
@@ -27,6 +27,7 @@ import { PictureXform } from "../../xlsx/xform/sheet/picture-xform.js";
27
27
  import { ConditionalFormattingsXform } from "../../xlsx/xform/sheet/cf/conditional-formattings-xform.js";
28
28
  import { HeaderFooterXform } from "../../xlsx/xform/sheet/header-footer-xform.js";
29
29
  import { RowBreaksXform } from "../../xlsx/xform/sheet/row-breaks-xform.js";
30
+ import { ColBreaksXform } from "../../xlsx/xform/sheet/col-breaks-xform.js";
30
31
  // since prepare and render are functional, we can use singletons
31
32
  const xform = {
32
33
  dataValidations: new DataValidationsXform(),
@@ -51,7 +52,8 @@ const xform = {
51
52
  picture: new PictureXform(),
52
53
  conditionalFormattings: new ConditionalFormattingsXform(),
53
54
  headerFooter: new HeaderFooterXform(),
54
- rowBreaks: new RowBreaksXform()
55
+ rowBreaks: new RowBreaksXform(),
56
+ colBreaks: new ColBreaksXform()
55
57
  };
56
58
  class WorksheetWriter {
57
59
  constructor(options) {
@@ -89,6 +91,7 @@ class WorksheetWriter {
89
91
  this.conditionalFormatting = [];
90
92
  // keep a record of all row and column pageBreaks
91
93
  this.rowBreaks = [];
94
+ this.colBreaks = [];
92
95
  // for default row height, outline levels, etc
93
96
  this.properties = Object.assign({}, {
94
97
  defaultRowHeight: 15,
@@ -193,6 +196,7 @@ class WorksheetWriter {
193
196
  this._writeBackground();
194
197
  this._writeHeaderFooter();
195
198
  this._writeRowBreaks();
199
+ this._writeColBreaks();
196
200
  // Legacy Data tag for comments
197
201
  this._writeLegacyData();
198
202
  this._writeCloseWorksheet();
@@ -543,6 +547,9 @@ class WorksheetWriter {
543
547
  _writeRowBreaks() {
544
548
  this.stream.write(xform.rowBreaks.toXml(this.rowBreaks));
545
549
  }
550
+ _writeColBreaks() {
551
+ this.stream.write(xform.colBreaks.toXml(this.colBreaks));
552
+ }
546
553
  _writeDataValidations() {
547
554
  this.stream.write(xform.dataValidations.toXml(this.dataValidations.model));
548
555
  }