@justybase/spreadsheet-tasks 1.0.0

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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +169 -0
  3. package/dist/BiffReaderWriter.d.ts +44 -0
  4. package/dist/BiffReaderWriter.d.ts.map +1 -0
  5. package/dist/BiffReaderWriter.js +282 -0
  6. package/dist/BiffReaderWriter.js.map +1 -0
  7. package/dist/BigBuffer.d.ts +24 -0
  8. package/dist/BigBuffer.d.ts.map +1 -0
  9. package/dist/BigBuffer.js +120 -0
  10. package/dist/BigBuffer.js.map +1 -0
  11. package/dist/ExcelReaderAbstract.d.ts +17 -0
  12. package/dist/ExcelReaderAbstract.d.ts.map +1 -0
  13. package/dist/ExcelReaderAbstract.js +25 -0
  14. package/dist/ExcelReaderAbstract.js.map +1 -0
  15. package/dist/ReaderFactory.d.ts +6 -0
  16. package/dist/ReaderFactory.d.ts.map +1 -0
  17. package/dist/ReaderFactory.js +56 -0
  18. package/dist/ReaderFactory.js.map +1 -0
  19. package/dist/XlsbReader.d.ts +24 -0
  20. package/dist/XlsbReader.d.ts.map +1 -0
  21. package/dist/XlsbReader.js +186 -0
  22. package/dist/XlsbReader.js.map +1 -0
  23. package/dist/XlsbWriter.d.ts +69 -0
  24. package/dist/XlsbWriter.d.ts.map +1 -0
  25. package/dist/XlsbWriter.js +802 -0
  26. package/dist/XlsbWriter.js.map +1 -0
  27. package/dist/XlsxReader.d.ts +30 -0
  28. package/dist/XlsxReader.d.ts.map +1 -0
  29. package/dist/XlsxReader.js +341 -0
  30. package/dist/XlsxReader.js.map +1 -0
  31. package/dist/XlsxWriter.d.ts +31 -0
  32. package/dist/XlsxWriter.d.ts.map +1 -0
  33. package/dist/XlsxWriter.js +415 -0
  34. package/dist/XlsxWriter.js.map +1 -0
  35. package/dist/index.d.ts +9 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +23 -0
  38. package/dist/index.js.map +1 -0
  39. package/docs/API.md +271 -0
  40. package/docs/BENCHMARK.md +129 -0
  41. package/docs/PUBLISHING.md +89 -0
  42. package/examples/basic-read.ts +109 -0
  43. package/examples/basic-write.ts +84 -0
  44. package/examples/large-dataset.ts +216 -0
  45. package/examples/multiple-sheets.ts +126 -0
  46. package/examples/streaming-example.ts +181 -0
  47. package/package.json +70 -0
@@ -0,0 +1,802 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.XlsbWriter = void 0;
40
+ const fs = __importStar(require("fs"));
41
+ const archiver_1 = __importDefault(require("archiver"));
42
+ const stream_1 = require("stream");
43
+ const BigBuffer_1 = require("./BigBuffer");
44
+ const INVALID_SHEET_NAME_CHARS = /[\\/*?[\]:]/g;
45
+ class XlsbWriter {
46
+ constructor(filePath) {
47
+ this.sheetCount = 0;
48
+ this.sheetList = [];
49
+ this.sstDic = new Map();
50
+ this.sstCntUnique = 0;
51
+ this.sstCntAll = 0;
52
+ this.colWidths = [];
53
+ this._autofilterIsOn = false;
54
+ // Streaming state
55
+ this.currentSheetBuffer = null;
56
+ this.currentSheetRowNum = 0;
57
+ this.currentSheetStartCol = 0;
58
+ this.currentSheetEndCol = 0;
59
+ this.currentSheetDoAutofilter = false;
60
+ this.isStreaming = false;
61
+ this.output = fs.createWriteStream(filePath);
62
+ this.archive = (0, archiver_1.default)('zip');
63
+ this.archive.pipe(this.output);
64
+ this._oaEpoch = Date.UTC(1899, 11, 30);
65
+ this._sheet1Bytes = Buffer.from([
66
+ 0x81, 0x01, 0x00, 0x93, 0x01, 0x17, 0xCB, 0x04,
67
+ 0x02, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
68
+ 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
69
+ 0xFF, 0x00, 0x00, 0x00, 0x00, 0x94, 0x01, 0x10,
70
+ 0x00, 0x00, 0x00, 0x00,
71
+ 0x00, 0x00, 0x00, 0x00,
72
+ 0x00, 0x00, 0x00, 0x00,
73
+ 0x00, 0x00, 0x00, 0x00,
74
+ 0x85, 0x01, 0x00, 0x89, 0x01, 0x1E, 0xDC, 0x03,
75
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76
+ 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
77
+ 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78
+ 0x00, 0x00, 0x00, 0x00,
79
+ 0x98, 0x01, 0x24, 0x03,
80
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
82
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84
+ 0x00, 0x00, 0x00, 0x8A, 0x01, 0x00, 0x86, 0x01,
85
+ 0x00, 0x25, 0x06, 0x01, 0x00, 0x02, 0x0E, 0x00,
86
+ 0x80, 0x95, 0x08, 0x02, 0x05, 0x00, 0x26, 0x00,
87
+ 0xE5, 0x03, 0x0C, 0xFF, 0xFF, 0xFF, 0xFF, 0x08,
88
+ 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x91,
89
+ 0x01, 0x00, 0x25, 0x06, 0x01, 0x00, 0x02, 0x0E,
90
+ 0x00, 0x80, 0x80, 0x08, 0x02, 0x05, 0x00, 0x26,
91
+ 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
92
+ 0x00, 0x00, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00,
93
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94
+ 0x00, 0x00, 0x00, 0x00, 0x07, 0x0C, 0x00, 0x00,
95
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96
+ 0x00, 0x00, 0x92, 0x01, 0x00, 0x97, 0x04, 0x42,
97
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
98
+ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
99
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
102
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
103
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
104
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
105
+ 0x00, 0x00,
106
+ 0xDD, 0x03, 0x02, 0x10, 0x00, 0xDC, 0x03, 0x30,
107
+ 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0xE6, 0x3F,
108
+ 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0xE6, 0x3F,
109
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x3F,
110
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x3F,
111
+ 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0xD3, 0x3F,
112
+ 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0xD3, 0x3F,
113
+ 0x25, 0x06, 0x01, 0x00, 0x00, 0x10, 0x00, 0x80,
114
+ 0x80, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x01,
115
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116
+ 0x00, 0x00, 0x00, 0x26, 0x00, 0x82, 0x01, 0x00
117
+ ]);
118
+ this._workbookBinStart = Buffer.from([
119
+ 0x83, 0x01, 0x00, 0x80, 0x01, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x78, 0x00, 0x6C, 0x00, 0x01, 0x00, 0x00, 0x00,
120
+ 0x37, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x00, 0x00, 0x32, 0x00, 0x34, 0x00, 0x33, 0x00, 0x32, 0x00, 0x36, 0x00, 0x99, 0x01, 0x0C, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121
+ 0x00, 0x00, 0x00, 0x25, 0x06, 0x01, 0x00, 0x03, 0x0F, 0x00, 0x80, 0x97, 0x10, 0x34, 0x18, 0x00, 0x00, 0x00, 0x43, 0x00, 0x3A, 0x00, 0x5C, 0x00, 0x73, 0x00, 0x71, 0x00, 0x6C, 0x00, 0x73, 0x00, 0x5C, 0x00,
122
+ 0x54, 0x00, 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0x79, 0x00, 0x5A, 0x00, 0x61, 0x00, 0x70, 0x00, 0x69, 0x00, 0x73, 0x00, 0x75, 0x00, 0x58, 0x00, 0x6C, 0x00, 0x73, 0x00, 0x62, 0x00, 0x5C, 0x00, 0x26, 0x00,
123
+ 0x25, 0x06, 0x01, 0x00, 0x00, 0x10, 0x00, 0x80, 0x81, 0x18, 0x82, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, 0x00, 0x31, 0x00, 0x33, 0x00, 0x5F, 0x00, 0x6E, 0x00, 0x63, 0x00,
124
+ 0x72, 0x00, 0x3A, 0x00, 0x31, 0x00, 0x5F, 0x00, 0x7B, 0x00, 0x31, 0x00, 0x36, 0x00, 0x35, 0x00, 0x30, 0x00, 0x38, 0x00, 0x44, 0x00, 0x36, 0x00, 0x39, 0x00, 0x2D, 0x00, 0x43, 0x00, 0x46, 0x00, 0x38, 0x00,
125
+ 0x37, 0x00, 0x2D, 0x00, 0x34, 0x00, 0x37, 0x00, 0x36, 0x00, 0x39, 0x00, 0x2D, 0x00, 0x38, 0x00, 0x34, 0x00, 0x35, 0x00, 0x36, 0x00, 0x2D, 0x00, 0x44, 0x00, 0x34, 0x00, 0x41, 0x00, 0x34, 0x00, 0x30, 0x00,
126
+ 0x31, 0x00, 0x31, 0x00, 0x33, 0x00, 0x31, 0x00, 0x35, 0x00, 0x36, 0x00, 0x37, 0x00, 0x7D, 0x00, 0x2F, 0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
127
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x00, 0x87, 0x01, 0x00, 0x25, 0x06, 0x01, 0x00, 0x02, 0x10, 0x00, 0x80, 0x80, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
128
+ 0x00, 0x00, 0x00, 0x00, 0x26, 0x00, 0x9E, 0x01, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x9E, 0x16, 0x00, 0x00, 0xB4, 0x69, 0x00, 0x00, 0xE8, 0x26, 0x00, 0x00, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
129
+ 0x00, 0x00, 0x00, 0x78, 0x88, 0x01, 0x00,
130
+ 0x8F, 0x01, 0x00
131
+ ]);
132
+ this._workbookBinMiddle = Buffer.from([0x90, 0x01, 0x00]);
133
+ this._workbookBinEnd = Buffer.from([
134
+ 0x9D, 0x01, 0x1A, 0x35, 0xEA, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0xFC, 0xA9, 0xF1, 0xD2, 0x4D, 0x62, 0x50, 0x3F, 0x01,
135
+ 0x00, 0x00, 0x00, 0x6A, 0x00, 0x9B, 0x01, 0x01, 0x00, 0x23, 0x04, 0x03, 0x0F, 0x00, 0x00, 0xAB, 0x10, 0x01, 0x01, 0x24, 0x00, 0x84, 0x01, 0x00
136
+ ]);
137
+ this._stylesBin = Buffer.from([
138
+ 0x96, 0x02, 0x00, 0xE7, 0x04, 0x04, 0x02,
139
+ 0x00, 0x00, 0x00, 0x2C, 0x2C, 0xA4, 0x00, 0x13,
140
+ 0x00, 0x00, 0x00, 0x79, 0x00, 0x79, 0x00, 0x79,
141
+ 0x00, 0x79, 0x00, 0x5C, 0x00, 0x2D, 0x00, 0x6D,
142
+ 0x00, 0x6D, 0x00, 0x5C, 0x00, 0x2D, 0x00, 0x64,
143
+ 0x00, 0x64, 0x00, 0x5C, 0x00, 0x20, 0x00, 0x68,
144
+ 0x00, 0x68, 0x00, 0x3A, 0x00, 0x6D, 0x00, 0x6D,
145
+ 0x00, 0x2C, 0x1E, 0xA6, 0x00, 0x0C, 0x00, 0x00,
146
+ 0x00, 0x79, 0x00, 0x79, 0x00, 0x79, 0x00, 0x79,
147
+ 0x00, 0x5C, 0x00, 0x2D, 0x00, 0x6D, 0x00, 0x6D,
148
+ 0x00, 0x5C, 0x00, 0x2D, 0x00, 0x64, 0x00, 0x64,
149
+ 0x00, 0xE8, 0x04, 0x00, 0xE3, 0x04, 0x04, 0x01,
150
+ 0x00, 0x00, 0x00,
151
+ 0x2B, 0x27, 0xDC, 0x00, 0x00, 0x00, 0x90, 0x01,
152
+ 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x07, 0x01,
153
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x02, 0x07,
154
+ 0x00, 0x00, 0x00, 0x43, 0x00, 0x61, 0x00, 0x6C,
155
+ 0x00, 0x69, 0x00, 0x62, 0x00, 0x72, 0x00, 0x69,
156
+ 0x00,
157
+ 0x2B, 0x27, 0xDC, 0x00, 0x01, 0x00, 0xBC, 0x02,
158
+ 0x00, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x07, 0x01,
159
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x02, 0x07,
160
+ 0x00, 0x00, 0x00, 0x43, 0x00, 0x61, 0x00, 0x6C,
161
+ 0x00, 0x69, 0x00, 0x62, 0x00, 0x72, 0x00, 0x69,
162
+ 0x00,
163
+ 0x25, 0x06, 0x01, 0x00, 0x02, 0x0E, 0x00, 0x80, 0x81, 0x08, 0x00, 0x26, 0x00, 0xE4, 0x04, 0x00, 0xDB, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00,
164
+ 0x2D, 0x44, 0x00, 0x00, 0x00, 0x00, 0x03, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x41, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
165
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
166
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167
+ 0x00, 0x2D, 0x44, 0x11, 0x00, 0x00, 0x00, 0x03, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x41, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
168
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
169
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
170
+ 0x00, 0x00, 0xDC, 0x04, 0x00, 0xE5, 0x04, 0x04, 0x01, 0x00, 0x00, 0x00, 0x2E, 0x33, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
171
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
172
+ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE6, 0x04, 0x00, 0xF2,
173
+ 0x04, 0x04, 0x01, 0x00, 0x00, 0x00, 0x2F, 0x10, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,
174
+ 0x00, 0xF3, 0x04, 0x00, 0xE9, 0x04, 0x04,
175
+ 0x04,
176
+ 0x00, 0x00, 0x00,
177
+ 0x2F, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,
178
+ 0x2F, 0x10, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x01, 0x00,
179
+ 0x2F, 0x10, 0x00, 0x00, 0xA6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x01, 0x00,
180
+ 0x2F, 0x10, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,
181
+ 0xEA, 0x04, 0x00, 0xEB, 0x04, 0x04, 0x01, 0x00,
182
+ 0x00, 0x00, 0x25, 0x06, 0x01, 0x00, 0x02, 0x11, 0x00, 0x80, 0x80, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
183
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x00, 0x30, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4E,
184
+ 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x6C, 0x00, 0x6E, 0x00, 0x79, 0x00, 0xEC, 0x04, 0x00, 0xF9, 0x03, 0x04, 0x00, 0x00,
185
+ 0x00, 0x00, 0xFA, 0x03, 0x00, 0xFC, 0x03, 0x50, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x54, 0x00, 0x61, 0x00, 0x62, 0x00, 0x6C,
186
+ 0x00, 0x65, 0x00, 0x53, 0x00, 0x74, 0x00, 0x79, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x4D, 0x00, 0x65, 0x00, 0x64, 0x00, 0x69, 0x00, 0x75, 0x00,
187
+ 0x6D, 0x00, 0x32, 0x00, 0x11, 0x00, 0x00, 0x00, 0x50, 0x00, 0x69, 0x00, 0x76, 0x00, 0x6F, 0x00, 0x74, 0x00, 0x53, 0x00, 0x74, 0x00, 0x79,
188
+ 0x00, 0x6C, 0x00, 0x65, 0x00, 0x4C, 0x00, 0x69, 0x00, 0x67, 0x00, 0x68, 0x00, 0x74, 0x00, 0x31, 0x00, 0x36, 0x00, 0xFD, 0x03, 0x00, 0x23,
189
+ 0x04, 0x02, 0x0E, 0x00, 0x00, 0xEB, 0x08, 0x00, 0xF6, 0x08, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x53, 0x00, 0x6C, 0x00,
190
+ 0x69, 0x00, 0x63, 0x00, 0x65, 0x00, 0x72, 0x00, 0x53, 0x00, 0x74, 0x00, 0x79, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x4C, 0x00, 0x69, 0x00, 0x67,
191
+ 0x00, 0x68, 0x00, 0x74, 0x00, 0x31, 0x00, 0xF7, 0x08, 0x00, 0xEC, 0x08, 0x00, 0x24, 0x00, 0x23, 0x04, 0x03, 0x0F, 0x00, 0x00, 0xB0, 0x10,
192
+ 0x00, 0xB2, 0x10, 0x32, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x54, 0x00, 0x69, 0x00, 0x6D, 0x00, 0x65, 0x00, 0x53, 0x00, 0x6C,
193
+ 0x00, 0x69, 0x00, 0x63, 0x00, 0x65, 0x00, 0x72, 0x00, 0x53, 0x00, 0x74, 0x00, 0x79, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x4C, 0x00, 0x69, 0x00,
194
+ 0x67, 0x00, 0x68, 0x00, 0x74, 0x00, 0x31, 0x00, 0xB3, 0x10, 0x00, 0xB1, 0x10, 0x00, 0x24, 0x00, 0x97, 0x02, 0x00
195
+ ]);
196
+ this._binaryIndexBin = Buffer.from([
197
+ 0x2A, 0x18, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x95,
198
+ 0x02, 0x00
199
+ ]);
200
+ this._rRkIntegerLowerLimit = -1 << 29;
201
+ this._rRkIntegerUpperLimit = (1 << 29) - 1;
202
+ this._autoFilterStartBytes = Buffer.from([0xA1, 0x01, 0x10]);
203
+ this._autoFilterEndBytes = Buffer.from([0xA2, 0x01, 0x00]);
204
+ this._stickHeaderA1bytes = Buffer.from([
205
+ 0x97, 0x01, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00,
206
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
207
+ 0x00, 0xF0, 0x3F, 0x01, 0x00, 0x00, 0x00, 0x00,
208
+ 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03
209
+ ]);
210
+ this._magicFilterExcel2016Fix0 = Buffer.from([0xE1, 0x02, 0x00, 0xE5, 0x02, 0x00, 0xEA, 0x02]);
211
+ this._magicFilterExcel2016Fix1 = Buffer.from([
212
+ 0x27, 0x46, 0x21, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x5F,
213
+ 0x00, 0x46, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x74, 0x00, 0x65, 0x00, 0x72, 0x00, 0x44, 0x00, 0x61,
214
+ 0x00, 0x74, 0x00, 0x61, 0x00, 0x62, 0x00, 0x61, 0x00, 0x73, 0x00, 0x65, 0x00, 0x0F, 0x00, 0x00,
215
+ 0x00, 0x3B, 0xFF, 0x00
216
+ ]);
217
+ this._magicFilterExcel2016Fix2 = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF]);
218
+ }
219
+ _sanitizeSheetName(name) {
220
+ if (!name || typeof name !== 'string') {
221
+ return `Sheet${this.sheetCount + 1}`;
222
+ }
223
+ let sanitized = name.replace(INVALID_SHEET_NAME_CHARS, '_');
224
+ if (sanitized.length > 31) {
225
+ sanitized = sanitized.substring(0, 31);
226
+ }
227
+ if (sanitized.trim().length === 0) {
228
+ sanitized = `Sheet${this.sheetCount + 1}`;
229
+ }
230
+ return sanitized;
231
+ }
232
+ addSheet(sheetName, hidden = false) {
233
+ const sanitizedName = this._sanitizeSheetName(sheetName);
234
+ this.sheetCount++;
235
+ this.sheetList.push({
236
+ name: sanitizedName,
237
+ pathInArchive: `xl/worksheets/sheet${this.sheetCount}.bin`,
238
+ hidden: hidden,
239
+ nameInArchive: `sheet${this.sheetCount}.bin`,
240
+ sheetId: this.sheetCount,
241
+ filterHeaderRange: null
242
+ });
243
+ }
244
+ /**
245
+ * Start a new sheet in streaming mode. Call writeRow() for each row, then endSheet() when done.
246
+ * @param sheetName Name of the sheet
247
+ * @param columnCount Number of columns in the sheet
248
+ * @param headers Optional header row
249
+ * @param options Optional settings (hidden, doAutofilter)
250
+ */
251
+ startSheet(sheetName, columnCount, headers, options = {}) {
252
+ if (this.isStreaming) {
253
+ throw new Error('Already in streaming mode. Call endSheet() first.');
254
+ }
255
+ const { hidden = false, doAutofilter = true } = options;
256
+ // Add sheet metadata
257
+ this.addSheet(sheetName, hidden);
258
+ // Initialize streaming state
259
+ this.isStreaming = true;
260
+ this.currentSheetBuffer = new BigBuffer_1.BigBuffer();
261
+ this.currentSheetRowNum = 0;
262
+ this.currentSheetStartCol = 0;
263
+ this.currentSheetEndCol = columnCount;
264
+ this.currentSheetDoAutofilter = doAutofilter && headers !== undefined;
265
+ const bigBuf = this.currentSheetBuffer;
266
+ // Initialize column widths
267
+ this.colWidths = new Array(columnCount).fill(-1.0);
268
+ if (headers) {
269
+ for (let i = 0; i < columnCount; i++) {
270
+ const len = headers[i] ? headers[i].length : 0;
271
+ let width = 1.25 * len + 2;
272
+ if (width > 80)
273
+ width = 80;
274
+ if (this.colWidths[i] < width)
275
+ this.colWidths[i] = width;
276
+ }
277
+ }
278
+ // Write sheet header
279
+ const sheetHeader = Buffer.from(this._sheet1Bytes);
280
+ sheetHeader.writeInt32LE(this.currentSheetStartCol, 40);
281
+ sheetHeader.writeInt32LE(this.currentSheetEndCol, 44);
282
+ if (this.sheetCount !== 1) {
283
+ sheetHeader[54] = 0x9C;
284
+ }
285
+ bigBuf.write(sheetHeader.subarray(0, 84));
286
+ // Write sticky header if autofilter is on
287
+ if (this.currentSheetDoAutofilter) {
288
+ bigBuf.write(this._stickHeaderA1bytes);
289
+ }
290
+ bigBuf.write(sheetHeader.subarray(84, 159));
291
+ // Write column definitions
292
+ bigBuf.writeByte(134);
293
+ bigBuf.writeByte(3);
294
+ for (let i = this.currentSheetStartCol; i < this.currentSheetEndCol; i++) {
295
+ bigBuf.writeByte(0);
296
+ bigBuf.writeByte(60);
297
+ bigBuf.writeByte(18);
298
+ bigBuf.writeInt32LE(i);
299
+ bigBuf.writeInt32LE(i);
300
+ const width = this.colWidths[i] > 0 ? Math.floor(this.colWidths[i]) : 10;
301
+ bigBuf.writeByte(0);
302
+ bigBuf.writeByte(Math.max(0, Math.min(255, width)));
303
+ bigBuf.writeByte(0);
304
+ bigBuf.writeByte(0);
305
+ bigBuf.writeByte(0);
306
+ bigBuf.writeByte(0);
307
+ bigBuf.writeByte(0);
308
+ bigBuf.writeByte(0);
309
+ bigBuf.writeByte(2);
310
+ }
311
+ bigBuf.writeByte(0);
312
+ bigBuf.writeByte(135);
313
+ bigBuf.writeByte(3);
314
+ bigBuf.writeByte(0);
315
+ bigBuf.write(sheetHeader.subarray(159, 175));
316
+ bigBuf.write(Buffer.from([38, 0]));
317
+ // Write header row if provided
318
+ if (headers) {
319
+ this.createRowHeader(bigBuf, this.currentSheetRowNum, this.currentSheetStartCol, this.currentSheetEndCol);
320
+ for (let c = 0; c < headers.length; c++) {
321
+ this.writeString(bigBuf, headers[c], c, true);
322
+ }
323
+ this.currentSheetRowNum++;
324
+ }
325
+ }
326
+ /**
327
+ * Write a single row in streaming mode. Must be called between startSheet() and endSheet().
328
+ * @param row Array of cell values
329
+ */
330
+ writeRow(row) {
331
+ if (!this.isStreaming || !this.currentSheetBuffer) {
332
+ throw new Error('Not in streaming mode. Call startSheet() first.');
333
+ }
334
+ if (row.length !== this.currentSheetEndCol - this.currentSheetStartCol) {
335
+ throw new Error(`Row length mismatch. Expected ${this.currentSheetEndCol - this.currentSheetStartCol} columns, got ${row.length}`);
336
+ }
337
+ const bigBuf = this.currentSheetBuffer;
338
+ // Write row header
339
+ this.createRowHeader(bigBuf, this.currentSheetRowNum, this.currentSheetStartCol, this.currentSheetEndCol);
340
+ // Write each cell
341
+ for (let c = 0; c < row.length; c++) {
342
+ const val = row[c];
343
+ if (val === null || val === undefined)
344
+ continue;
345
+ if (typeof val === 'number') {
346
+ if (Number.isInteger(val)) {
347
+ if (val >= this._rRkIntegerLowerLimit && val <= this._rRkIntegerUpperLimit) {
348
+ this.writeRkNumberInteger(bigBuf, val, c);
349
+ }
350
+ else {
351
+ this.writeDouble(bigBuf, val, c);
352
+ }
353
+ }
354
+ else {
355
+ this.writeDouble(bigBuf, val, c);
356
+ }
357
+ }
358
+ else if (typeof val === 'bigint') {
359
+ this.writeString(bigBuf, val.toString(), c);
360
+ }
361
+ else if (typeof val === 'boolean') {
362
+ this.writeBool(bigBuf, val, c);
363
+ }
364
+ else if (val instanceof Date) {
365
+ this.writeDateTime(bigBuf, val, c);
366
+ }
367
+ else {
368
+ this.writeString(bigBuf, val.toString(), c);
369
+ }
370
+ }
371
+ this.currentSheetRowNum++;
372
+ }
373
+ /**
374
+ * Finalize the current streaming sheet and add it to the archive.
375
+ * Must be called after startSheet() and writeRow() calls.
376
+ */
377
+ endSheet() {
378
+ if (!this.isStreaming || !this.currentSheetBuffer) {
379
+ throw new Error('Not in streaming mode. Call startSheet() first.');
380
+ }
381
+ const bigBuf = this.currentSheetBuffer;
382
+ const sheetHeader = Buffer.from(this._sheet1Bytes);
383
+ // Write sheet footer sections
384
+ bigBuf.write(sheetHeader.subarray(218, 290));
385
+ // Write autofilter if enabled
386
+ if (this.currentSheetDoAutofilter) {
387
+ this._autofilterIsOn = true;
388
+ const endRow = this.currentSheetRowNum;
389
+ bigBuf.write(this._autoFilterStartBytes);
390
+ const rowBuf = Buffer.alloc(8);
391
+ rowBuf.writeInt32LE(0, 0);
392
+ rowBuf.writeInt32LE(endRow - 1, 4);
393
+ bigBuf.write(rowBuf);
394
+ const colBuf = Buffer.alloc(8);
395
+ colBuf.writeInt32LE(this.currentSheetStartCol, 0);
396
+ colBuf.writeInt32LE(this.currentSheetEndCol - 1, 4);
397
+ bigBuf.write(colBuf);
398
+ bigBuf.write(this._autoFilterEndBytes);
399
+ // Update sheet metadata with filter info
400
+ const sheet = this.sheetList[this.sheetCount - 1];
401
+ sheet.filterData = {
402
+ startRow: 0,
403
+ endRow: this.currentSheetRowNum - 1,
404
+ startColumn: this.currentSheetStartCol,
405
+ endColumn: this.currentSheetEndCol - 1
406
+ };
407
+ }
408
+ // Write final sheet footer
409
+ bigBuf.write(sheetHeader.subarray(290));
410
+ // Append to archive as a stream
411
+ this.archive.append(stream_1.Readable.from(bigBuf.getChunks()), {
412
+ name: this.sheetList[this.sheetCount - 1].pathInArchive
413
+ });
414
+ // Reset streaming state
415
+ this.isStreaming = false;
416
+ this.currentSheetBuffer = null;
417
+ this.currentSheetRowNum = 0;
418
+ this.currentSheetStartCol = 0;
419
+ this.currentSheetEndCol = 0;
420
+ this.currentSheetDoAutofilter = false;
421
+ }
422
+ writeSheet(rows, headers = null, doAutofilter = true) {
423
+ const bigBuf = new BigBuffer_1.BigBuffer();
424
+ let columnCount = 0;
425
+ if (rows.length > 0) {
426
+ columnCount = rows[0].length;
427
+ }
428
+ else if (headers) {
429
+ columnCount = headers.length;
430
+ }
431
+ this.colWidths = new Array(columnCount).fill(-1.0);
432
+ if (headers) {
433
+ for (let i = 0; i < columnCount; i++) {
434
+ const len = headers[i] ? headers[i].length : 0;
435
+ let width = 1.25 * len + 2;
436
+ if (width > 80)
437
+ width = 80;
438
+ if (this.colWidths[i] < width)
439
+ this.colWidths[i] = width;
440
+ }
441
+ }
442
+ for (let r = 0; r < Math.min(rows.length, 100); r++) {
443
+ const row = rows[r];
444
+ for (let c = 0; c < row.length; c++) {
445
+ const val = row[c];
446
+ const len = val ? val.toString().length : 0;
447
+ let width = 1.25 * len + 2;
448
+ if (width > 80)
449
+ width = 80;
450
+ if (this.colWidths[c] < width)
451
+ this.colWidths[c] = width;
452
+ }
453
+ }
454
+ const sheetHeader = Buffer.from(this._sheet1Bytes);
455
+ const startCol = 0;
456
+ const endCol = columnCount;
457
+ sheetHeader.writeInt32LE(startCol, 40);
458
+ sheetHeader.writeInt32LE(endCol, 44);
459
+ if (this.sheetCount !== 1) {
460
+ sheetHeader[54] = 0x9C;
461
+ }
462
+ bigBuf.write(sheetHeader.subarray(0, 84));
463
+ if (doAutofilter && headers) {
464
+ bigBuf.write(this._stickHeaderA1bytes);
465
+ }
466
+ bigBuf.write(sheetHeader.subarray(84, 159));
467
+ bigBuf.writeByte(134);
468
+ bigBuf.writeByte(3);
469
+ for (let i = startCol; i < endCol; i++) {
470
+ bigBuf.writeByte(0);
471
+ bigBuf.writeByte(60);
472
+ bigBuf.writeByte(18);
473
+ bigBuf.writeInt32LE(i);
474
+ bigBuf.writeInt32LE(i);
475
+ const width = this.colWidths[i] > 0 ? Math.floor(this.colWidths[i]) : 10;
476
+ bigBuf.writeByte(0);
477
+ bigBuf.writeByte(Math.max(0, Math.min(255, width)));
478
+ bigBuf.writeByte(0);
479
+ bigBuf.writeByte(0);
480
+ bigBuf.writeByte(0);
481
+ bigBuf.writeByte(0);
482
+ bigBuf.writeByte(0);
483
+ bigBuf.writeByte(0);
484
+ bigBuf.writeByte(2);
485
+ }
486
+ bigBuf.writeByte(0);
487
+ bigBuf.writeByte(135);
488
+ bigBuf.writeByte(3);
489
+ bigBuf.writeByte(0);
490
+ bigBuf.write(sheetHeader.subarray(159, 175));
491
+ bigBuf.write(Buffer.from([38, 0]));
492
+ let rowNum = 0;
493
+ if (headers) {
494
+ this.createRowHeader(bigBuf, rowNum, startCol, endCol);
495
+ for (let c = 0; c < headers.length; c++) {
496
+ this.writeString(bigBuf, headers[c], c, true);
497
+ }
498
+ rowNum++;
499
+ }
500
+ for (let r = 0; r < rows.length; r++) {
501
+ this.createRowHeader(bigBuf, rowNum, startCol, endCol);
502
+ const row = rows[r];
503
+ for (let c = 0; c < row.length; c++) {
504
+ const val = row[c];
505
+ if (val === null || val === undefined)
506
+ continue;
507
+ if (typeof val === 'number') {
508
+ if (Number.isInteger(val)) {
509
+ if (val >= this._rRkIntegerLowerLimit && val <= this._rRkIntegerUpperLimit) {
510
+ this.writeRkNumberInteger(bigBuf, val, c);
511
+ }
512
+ else {
513
+ this.writeDouble(bigBuf, val, c);
514
+ }
515
+ }
516
+ else {
517
+ this.writeDouble(bigBuf, val, c);
518
+ }
519
+ }
520
+ else if (typeof val === 'bigint') {
521
+ this.writeString(bigBuf, val.toString(), c);
522
+ }
523
+ else if (typeof val === 'boolean') {
524
+ this.writeBool(bigBuf, val, c);
525
+ }
526
+ else if (val instanceof Date) {
527
+ this.writeDateTime(bigBuf, val, c);
528
+ }
529
+ else {
530
+ this.writeString(bigBuf, val.toString(), c);
531
+ }
532
+ }
533
+ rowNum++;
534
+ }
535
+ bigBuf.write(sheetHeader.subarray(218, 290));
536
+ if (doAutofilter && headers) {
537
+ this._autofilterIsOn = true;
538
+ const endRow = rows.length + 1;
539
+ bigBuf.write(this._autoFilterStartBytes);
540
+ const rowBuf = Buffer.alloc(8);
541
+ rowBuf.writeInt32LE(0, 0);
542
+ rowBuf.writeInt32LE(endRow - 1, 4);
543
+ bigBuf.write(rowBuf);
544
+ const colBuf = Buffer.alloc(8);
545
+ colBuf.writeInt32LE(startCol, 0);
546
+ colBuf.writeInt32LE(endCol - 1, 4);
547
+ bigBuf.write(colBuf);
548
+ bigBuf.write(this._autoFilterEndBytes);
549
+ const sheet = this.sheetList[this.sheetCount - 1];
550
+ sheet.filterData = {
551
+ startRow: 0,
552
+ endRow: rows.length,
553
+ startColumn: startCol,
554
+ endColumn: endCol - 1
555
+ };
556
+ }
557
+ bigBuf.write(sheetHeader.subarray(290));
558
+ this.archive.append(stream_1.Readable.from(bigBuf.getChunks()), { name: this.sheetList[this.sheetCount - 1].pathInArchive });
559
+ }
560
+ createRowHeader(bigBuf, rowNumber, startCol, endCol) {
561
+ bigBuf.ensureCapacity(27);
562
+ bigBuf.writeUnsafeByte(0);
563
+ bigBuf.writeUnsafeByte(25);
564
+ bigBuf.writeUnsafeInt32LE(rowNumber);
565
+ bigBuf.writeUnsafeInt32LE(0);
566
+ bigBuf.writeUnsafeByte(44);
567
+ bigBuf.writeUnsafeByte(1);
568
+ bigBuf.writeUnsafeByte(0);
569
+ bigBuf.writeUnsafeByte(0);
570
+ bigBuf.writeUnsafeByte(0);
571
+ bigBuf.writeUnsafeByte(1);
572
+ bigBuf.writeUnsafeByte(0);
573
+ bigBuf.writeUnsafeByte(0);
574
+ bigBuf.writeUnsafeByte(0);
575
+ bigBuf.writeUnsafeInt32LE(startCol);
576
+ bigBuf.writeUnsafeInt32LE(endCol);
577
+ }
578
+ writeRkNumberInteger(bigBuf, val, colNum, styleNum = 0) {
579
+ bigBuf.ensureCapacity(14);
580
+ bigBuf.writeUnsafeByte(2);
581
+ bigBuf.writeUnsafeByte(12);
582
+ bigBuf.writeUnsafeInt32LE(colNum);
583
+ bigBuf.writeUnsafeByte(styleNum);
584
+ bigBuf.writeUnsafeByte(0);
585
+ bigBuf.writeUnsafeByte(0);
586
+ bigBuf.writeUnsafeByte(0);
587
+ const rkVal = (val << 2) | 2;
588
+ bigBuf.writeUnsafeInt32LE(rkVal);
589
+ }
590
+ writeDouble(bigBuf, val, colNum, styleNum = 0) {
591
+ bigBuf.ensureCapacity(18);
592
+ bigBuf.writeUnsafeByte(5);
593
+ bigBuf.writeUnsafeByte(16);
594
+ bigBuf.writeUnsafeInt32LE(colNum);
595
+ bigBuf.writeUnsafeByte(styleNum);
596
+ bigBuf.writeUnsafeByte(0);
597
+ bigBuf.writeUnsafeByte(0);
598
+ bigBuf.writeUnsafeByte(0);
599
+ bigBuf.writeUnsafeDoubleLE(val);
600
+ }
601
+ writeBool(bigBuf, val, colNum) {
602
+ bigBuf.ensureCapacity(13);
603
+ bigBuf.writeUnsafeByte(0x04);
604
+ bigBuf.writeUnsafeByte(9);
605
+ bigBuf.writeUnsafeInt32LE(colNum);
606
+ bigBuf.writeUnsafeInt32LE(0);
607
+ bigBuf.writeUnsafeByte(val ? 1 : 0);
608
+ }
609
+ writeDateTime(bigBuf, date, colNum) {
610
+ // Use UTC time to avoid timezone conversion issues
611
+ const oaDate = (date.getTime() - this._oaEpoch) / 86400000;
612
+ this.writeDouble(bigBuf, oaDate, colNum, 1);
613
+ }
614
+ writeString(bigBuf, val, colNum, bolded = false) {
615
+ let index;
616
+ if (this.sstDic.has(val)) {
617
+ index = this.sstDic.get(val);
618
+ }
619
+ else {
620
+ index = this.sstCntUnique;
621
+ this.sstDic.set(val, index);
622
+ this.sstCntUnique++;
623
+ }
624
+ this.sstCntAll++;
625
+ bigBuf.ensureCapacity(17);
626
+ bigBuf.writeUnsafeByte(7);
627
+ bigBuf.writeUnsafeByte(12);
628
+ bigBuf.writeUnsafeInt32LE(colNum);
629
+ bigBuf.writeUnsafeByte(bolded ? 3 : 0);
630
+ bigBuf.writeUnsafeByte(0);
631
+ bigBuf.writeUnsafeByte(0);
632
+ bigBuf.writeUnsafeByte(0);
633
+ bigBuf.writeUnsafeInt32LE(index);
634
+ }
635
+ saveSst() {
636
+ const bigBuf = new BigBuffer_1.BigBuffer();
637
+ bigBuf.writeByte(159);
638
+ bigBuf.writeByte(1);
639
+ bigBuf.writeByte(8);
640
+ bigBuf.writeInt32LE(this.sstCntUnique);
641
+ bigBuf.writeInt32LE(this.sstCntAll);
642
+ for (const [txt] of this.sstDic) {
643
+ const txtLen = txt.length;
644
+ bigBuf.writeByte(19);
645
+ const recLen = 5 + 2 * txtLen;
646
+ if (recLen >= 128) {
647
+ bigBuf.writeByte(128 + (recLen % 128));
648
+ const tmp = recLen >> 7;
649
+ if (tmp >= 256) {
650
+ bigBuf.writeByte(128 + (tmp % 128));
651
+ }
652
+ else {
653
+ bigBuf.writeByte(tmp);
654
+ }
655
+ bigBuf.writeByte(recLen >> 14);
656
+ if ((recLen >> 14) > 0) {
657
+ bigBuf.writeByte(0);
658
+ }
659
+ }
660
+ else {
661
+ bigBuf.writeByte(recLen & 0xFF);
662
+ bigBuf.writeByte((recLen >> 8) & 0xFF);
663
+ }
664
+ bigBuf.writeInt32LE(txtLen);
665
+ bigBuf.writeUtf16LE(txt);
666
+ }
667
+ bigBuf.writeByte(160);
668
+ bigBuf.writeByte(1);
669
+ bigBuf.writeByte(0);
670
+ this.archive.append(stream_1.Readable.from(bigBuf.getChunks()), { name: 'xl/sharedStrings.bin' });
671
+ }
672
+ _writeFilterDefinedName(wbBuffers, sheet, sheetNum) {
673
+ const filterData = sheet.filterData;
674
+ const sheetIndex = sheet.sheetId - 1;
675
+ const fix1 = Buffer.alloc(this._magicFilterExcel2016Fix1.length);
676
+ this._magicFilterExcel2016Fix1.copy(fix1);
677
+ const lastIdx = this._magicFilterExcel2016Fix1.length - 2;
678
+ fix1[7] = sheetIndex;
679
+ fix1[lastIdx] = sheetNum;
680
+ wbBuffers.push(fix1);
681
+ const rowBuf = Buffer.alloc(8);
682
+ rowBuf.writeInt32LE(filterData.startRow, 0);
683
+ rowBuf.writeInt32LE(filterData.endRow, 4);
684
+ wbBuffers.push(rowBuf);
685
+ const colBuf = Buffer.alloc(4);
686
+ colBuf.writeInt16LE(filterData.startColumn, 0);
687
+ colBuf.writeInt16LE(filterData.endColumn, 2);
688
+ wbBuffers.push(colBuf);
689
+ wbBuffers.push(this._magicFilterExcel2016Fix2);
690
+ }
691
+ finalize() {
692
+ return new Promise((resolve, reject) => {
693
+ try {
694
+ this.saveSst();
695
+ this.archive.append(this._stylesBin, { name: 'xl/styles.bin' });
696
+ const wbBuffers = [];
697
+ wbBuffers.push(this._workbookBinStart);
698
+ for (const sheet of this.sheetList) {
699
+ const rId = `rId${sheet.sheetId}`;
700
+ const recLen = 4 + 12 + sheet.name.length * 2 + rId.length * 2;
701
+ const buf = Buffer.alloc(3 + recLen);
702
+ buf[0] = 156;
703
+ buf[1] = 1;
704
+ buf[2] = recLen;
705
+ let pos = 3;
706
+ buf.writeInt32LE(sheet.hidden ? 1 : 0, pos);
707
+ pos += 4;
708
+ buf.writeInt32LE(sheet.sheetId, pos);
709
+ pos += 4;
710
+ buf.writeInt32LE(rId.length, pos);
711
+ pos += 4;
712
+ for (let i = 0; i < rId.length; i++) {
713
+ const c = rId.charCodeAt(i);
714
+ buf[pos++] = c & 0xFF;
715
+ buf[pos++] = (c >> 8) & 0xFF;
716
+ }
717
+ buf.writeInt32LE(sheet.name.length, pos);
718
+ pos += 4;
719
+ for (let i = 0; i < sheet.name.length; i++) {
720
+ const c = sheet.name.charCodeAt(i);
721
+ buf[pos++] = c & 0xFF;
722
+ buf[pos++] = (c >> 8) & 0xFF;
723
+ }
724
+ wbBuffers.push(buf);
725
+ }
726
+ wbBuffers.push(this._workbookBinMiddle);
727
+ if (this._autofilterIsOn) {
728
+ const filteredSheets = this.sheetList.filter(s => s.filterData);
729
+ const cnt = filteredSheets.length;
730
+ if (cnt > 0) {
731
+ wbBuffers.push(this._magicFilterExcel2016Fix0);
732
+ const firstByte = 0x10 + (cnt - 1) * 0x0C;
733
+ const countBuf = Buffer.from([firstByte, cnt, 0x00, 0x00, 0x00]);
734
+ wbBuffers.push(countBuf);
735
+ for (let nm = 0; nm < cnt; nm++) {
736
+ const sheetIndex = filteredSheets[nm].sheetId - 1;
737
+ const idxBuf = Buffer.alloc(12);
738
+ idxBuf.writeInt32LE(0, 0);
739
+ idxBuf[4] = sheetIndex;
740
+ idxBuf[8] = sheetIndex;
741
+ wbBuffers.push(idxBuf);
742
+ }
743
+ wbBuffers.push(Buffer.from([0xE2, 0x02, 0x00]));
744
+ for (let sheetNum = 0; sheetNum < cnt; sheetNum++) {
745
+ const sheet = filteredSheets[sheetNum];
746
+ this._writeFilterDefinedName(wbBuffers, sheet, sheetNum);
747
+ }
748
+ }
749
+ }
750
+ wbBuffers.push(this._workbookBinEnd);
751
+ this.archive.append(Buffer.concat(wbBuffers), { name: 'xl/workbook.bin' });
752
+ for (const sheet of this.sheetList) {
753
+ this.archive.append(this._binaryIndexBin, { name: `xl/worksheets/binaryIndex${sheet.sheetId}.bin` });
754
+ }
755
+ let contentTypes = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
756
+ <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
757
+ <Default Extension="bin" ContentType="application/vnd.ms-excel.sheet.binary.macroEnabled.main"/>
758
+ <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
759
+ <Default Extension="xml" ContentType="application/xml"/>`;
760
+ for (const sheet of this.sheetList) {
761
+ contentTypes += `<Override PartName="/${sheet.pathInArchive}" ContentType="application/vnd.ms-excel.worksheet"/>`;
762
+ contentTypes += `<Override PartName="/xl/worksheets/binaryIndex${sheet.sheetId}.bin" ContentType="application/vnd.ms-excel.binIndexWs"/>`;
763
+ }
764
+ contentTypes += `<Override PartName="/xl/styles.bin" ContentType="application/vnd.ms-excel.styles"/>
765
+ <Override PartName="/xl/sharedStrings.bin" ContentType="application/vnd.ms-excel.sharedStrings"/>
766
+ </Types>`;
767
+ this.archive.append(contentTypes, { name: '[Content_Types].xml' });
768
+ let wbRels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
769
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">`;
770
+ for (const sheet of this.sheetList) {
771
+ const rId = `rId${sheet.sheetId}`;
772
+ wbRels += `<Relationship Id="${rId}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/${sheet.nameInArchive}"/>`;
773
+ }
774
+ wbRels += `<Relationship Id="rId${this.sheetList.length + 2}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.bin"/>
775
+ <Relationship Id="rId${this.sheetList.length + 3}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.bin"/>
776
+ </Relationships>`;
777
+ this.archive.append(wbRels, { name: 'xl/_rels/workbook.bin.rels' });
778
+ const globalRels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
779
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
780
+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.bin"/>
781
+ </Relationships>`;
782
+ this.archive.append(globalRels, { name: '_rels/.rels' });
783
+ for (const sheet of this.sheetList) {
784
+ const wsRels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
785
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
786
+ <Relationship Id="rId1" Type="http://schemas.microsoft.com/office/2006/relationships/xlBinaryIndex" Target="binaryIndex${sheet.sheetId}.bin"/>
787
+ </Relationships>`;
788
+ this.archive.append(wsRels, { name: `xl/worksheets/_rels/${sheet.nameInArchive}.rels` });
789
+ }
790
+ this.output.on('close', () => resolve());
791
+ this.archive.on('error', (err) => reject(err));
792
+ this.archive.finalize();
793
+ }
794
+ catch (err) {
795
+ reject(err);
796
+ }
797
+ });
798
+ }
799
+ }
800
+ exports.XlsbWriter = XlsbWriter;
801
+ exports.default = XlsbWriter;
802
+ //# sourceMappingURL=XlsbWriter.js.map