@justybase/spreadsheet-tasks 1.3.3 → 2.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.
- package/CHANGELOG.md +38 -0
- package/README.md +25 -16
- package/browser/browser-spreadsheet.js +3037 -0
- package/browser/justybase-spreadsheet.min.js +36 -0
- package/dist/cjs/index.d.ts +399 -0
- package/dist/cjs/index.js +3944 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.js +3889 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/docs/API.md +8 -9
- package/docs/PACKAGING.md +32 -0
- package/docs/PUBLISHING.md +8 -1
- package/examples/basic-read.ts +1 -1
- package/examples/formats-verify.ts +1 -2
- package/examples/large-dataset.ts +1 -1
- package/package.json +28 -13
- package/dist/BiffReaderWriter.d.ts +0 -44
- package/dist/BiffReaderWriter.d.ts.map +0 -1
- package/dist/BiffReaderWriter.js +0 -282
- package/dist/BiffReaderWriter.js.map +0 -1
- package/dist/BigBuffer.d.ts +0 -24
- package/dist/BigBuffer.d.ts.map +0 -1
- package/dist/BigBuffer.js +0 -120
- package/dist/BigBuffer.js.map +0 -1
- package/dist/ExcelReaderAbstract.d.ts +0 -17
- package/dist/ExcelReaderAbstract.d.ts.map +0 -1
- package/dist/ExcelReaderAbstract.js +0 -25
- package/dist/ExcelReaderAbstract.js.map +0 -1
- package/dist/Formats.d.ts +0 -34
- package/dist/Formats.d.ts.map +0 -1
- package/dist/Formats.js +0 -48
- package/dist/Formats.js.map +0 -1
- package/dist/ReaderFactory.d.ts +0 -6
- package/dist/ReaderFactory.d.ts.map +0 -1
- package/dist/ReaderFactory.js +0 -56
- package/dist/ReaderFactory.js.map +0 -1
- package/dist/XlsbReader.d.ts +0 -24
- package/dist/XlsbReader.d.ts.map +0 -1
- package/dist/XlsbReader.js +0 -186
- package/dist/XlsbReader.js.map +0 -1
- package/dist/XlsbWriter.d.ts +0 -80
- package/dist/XlsbWriter.d.ts.map +0 -1
- package/dist/XlsbWriter.js +0 -964
- package/dist/XlsbWriter.js.map +0 -1
- package/dist/XlsxReader.d.ts +0 -30
- package/dist/XlsxReader.d.ts.map +0 -1
- package/dist/XlsxReader.js +0 -341
- package/dist/XlsxReader.js.map +0 -1
- package/dist/XlsxWriter.d.ts +0 -51
- package/dist/XlsxWriter.d.ts.map +0 -1
- package/dist/XlsxWriter.js +0 -632
- package/dist/XlsxWriter.js.map +0 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -29
- package/dist/index.js.map +0 -1
package/dist/XlsbWriter.js
DELETED
|
@@ -1,964 +0,0 @@
|
|
|
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 Formats_1 = require("./Formats");
|
|
45
|
-
const INVALID_SHEET_NAME_CHARS = /[\\/*?[\]:]/g;
|
|
46
|
-
class XlsbWriter {
|
|
47
|
-
constructor(filePath) {
|
|
48
|
-
this.sheetCount = 0;
|
|
49
|
-
this.sheetList = [];
|
|
50
|
-
this.sstDic = new Map();
|
|
51
|
-
this.sstCntUnique = 0;
|
|
52
|
-
this.sstCntAll = 0;
|
|
53
|
-
this.colWidths = [];
|
|
54
|
-
this._autofilterIsOn = false;
|
|
55
|
-
this._nextFmtId = 167;
|
|
56
|
-
this._nextXfIdx = 4;
|
|
57
|
-
this._stFmtRecords = new Map();
|
|
58
|
-
// Streaming state
|
|
59
|
-
this.currentSheetBuffer = null;
|
|
60
|
-
this.currentSheetRowNum = 0;
|
|
61
|
-
this.currentSheetStartCol = 0;
|
|
62
|
-
this.currentSheetEndCol = 0;
|
|
63
|
-
this.currentSheetDoAutofilter = false;
|
|
64
|
-
this.isStreaming = false;
|
|
65
|
-
this.output = fs.createWriteStream(filePath);
|
|
66
|
-
this.archive = (0, archiver_1.default)('zip');
|
|
67
|
-
this.archive.pipe(this.output);
|
|
68
|
-
this._oaEpoch = Date.UTC(1899, 11, 30);
|
|
69
|
-
this._sheet1Bytes = Buffer.from([
|
|
70
|
-
0x81, 0x01, 0x00, 0x93, 0x01, 0x17, 0xCB, 0x04,
|
|
71
|
-
0x02, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
72
|
-
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
73
|
-
0xFF, 0x00, 0x00, 0x00, 0x00, 0x94, 0x01, 0x10,
|
|
74
|
-
0x00, 0x00, 0x00, 0x00,
|
|
75
|
-
0x00, 0x00, 0x00, 0x00,
|
|
76
|
-
0x00, 0x00, 0x00, 0x00,
|
|
77
|
-
0x00, 0x00, 0x00, 0x00,
|
|
78
|
-
0x85, 0x01, 0x00, 0x89, 0x01, 0x1E, 0xDC, 0x03,
|
|
79
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
80
|
-
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
|
81
|
-
0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
82
|
-
0x00, 0x00, 0x00, 0x00,
|
|
83
|
-
0x98, 0x01, 0x24, 0x03,
|
|
84
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
85
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
|
86
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
87
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
88
|
-
0x00, 0x00, 0x00, 0x8A, 0x01, 0x00, 0x86, 0x01,
|
|
89
|
-
0x00, 0x25, 0x06, 0x01, 0x00, 0x02, 0x0E, 0x00,
|
|
90
|
-
0x80, 0x95, 0x08, 0x02, 0x05, 0x00, 0x26, 0x00,
|
|
91
|
-
0xE5, 0x03, 0x0C, 0xFF, 0xFF, 0xFF, 0xFF, 0x08,
|
|
92
|
-
0x00, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x91,
|
|
93
|
-
0x01, 0x00, 0x25, 0x06, 0x01, 0x00, 0x02, 0x0E,
|
|
94
|
-
0x00, 0x80, 0x80, 0x08, 0x02, 0x05, 0x00, 0x26,
|
|
95
|
-
0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
96
|
-
0x00, 0x00, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00,
|
|
97
|
-
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
98
|
-
0x00, 0x00, 0x00, 0x00, 0x07, 0x0C, 0x00, 0x00,
|
|
99
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
100
|
-
0x00, 0x00, 0x92, 0x01, 0x00, 0x97, 0x04, 0x42,
|
|
101
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
|
|
102
|
-
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
103
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
104
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
105
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
106
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
|
|
107
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
108
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
|
|
109
|
-
0x00, 0x00,
|
|
110
|
-
0xDD, 0x03, 0x02, 0x10, 0x00, 0xDC, 0x03, 0x30,
|
|
111
|
-
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0xE6, 0x3F,
|
|
112
|
-
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0xE6, 0x3F,
|
|
113
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x3F,
|
|
114
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x3F,
|
|
115
|
-
0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0xD3, 0x3F,
|
|
116
|
-
0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0xD3, 0x3F,
|
|
117
|
-
0x25, 0x06, 0x01, 0x00, 0x00, 0x10, 0x00, 0x80,
|
|
118
|
-
0x80, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x01,
|
|
119
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
120
|
-
0x00, 0x00, 0x00, 0x26, 0x00, 0x82, 0x01, 0x00
|
|
121
|
-
]);
|
|
122
|
-
this._workbookBinStart = Buffer.from([
|
|
123
|
-
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,
|
|
124
|
-
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,
|
|
125
|
-
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,
|
|
126
|
-
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,
|
|
127
|
-
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,
|
|
128
|
-
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,
|
|
129
|
-
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,
|
|
130
|
-
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,
|
|
131
|
-
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,
|
|
132
|
-
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,
|
|
133
|
-
0x00, 0x00, 0x00, 0x78, 0x88, 0x01, 0x00,
|
|
134
|
-
0x8F, 0x01, 0x00
|
|
135
|
-
]);
|
|
136
|
-
this._workbookBinMiddle = Buffer.from([0x90, 0x01, 0x00]);
|
|
137
|
-
this._workbookBinEnd = Buffer.from([
|
|
138
|
-
0x9D, 0x01, 0x1A, 0x35, 0xEA, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0xFC, 0xA9, 0xF1, 0xD2, 0x4D, 0x62, 0x50, 0x3F, 0x01,
|
|
139
|
-
0x00, 0x00, 0x00, 0x6A, 0x00, 0x9B, 0x01, 0x01, 0x00, 0x23, 0x04, 0x03, 0x0F, 0x00, 0x00, 0xAB, 0x10, 0x01, 0x01, 0x24, 0x00, 0x84, 0x01, 0x00
|
|
140
|
-
]);
|
|
141
|
-
this._stylesBin = Buffer.from([
|
|
142
|
-
0x96, 0x02, 0x00, 0xE7, 0x04, 0x04, 0x02,
|
|
143
|
-
0x00, 0x00, 0x00, 0x2C, 0x2C, 0xA4, 0x00, 0x13,
|
|
144
|
-
0x00, 0x00, 0x00, 0x79, 0x00, 0x79, 0x00, 0x79,
|
|
145
|
-
0x00, 0x79, 0x00, 0x5C, 0x00, 0x2D, 0x00, 0x6D,
|
|
146
|
-
0x00, 0x6D, 0x00, 0x5C, 0x00, 0x2D, 0x00, 0x64,
|
|
147
|
-
0x00, 0x64, 0x00, 0x5C, 0x00, 0x20, 0x00, 0x68,
|
|
148
|
-
0x00, 0x68, 0x00, 0x3A, 0x00, 0x6D, 0x00, 0x6D,
|
|
149
|
-
0x00, 0x2C, 0x1E, 0xA6, 0x00, 0x0C, 0x00, 0x00,
|
|
150
|
-
0x00, 0x79, 0x00, 0x79, 0x00, 0x79, 0x00, 0x79,
|
|
151
|
-
0x00, 0x5C, 0x00, 0x2D, 0x00, 0x6D, 0x00, 0x6D,
|
|
152
|
-
0x00, 0x5C, 0x00, 0x2D, 0x00, 0x64, 0x00, 0x64,
|
|
153
|
-
0x00, 0xE8, 0x04, 0x00, 0xE3, 0x04, 0x04, 0x01,
|
|
154
|
-
0x00, 0x00, 0x00,
|
|
155
|
-
0x2B, 0x27, 0xDC, 0x00, 0x00, 0x00, 0x90, 0x01,
|
|
156
|
-
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x07, 0x01,
|
|
157
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x02, 0x07,
|
|
158
|
-
0x00, 0x00, 0x00, 0x43, 0x00, 0x61, 0x00, 0x6C,
|
|
159
|
-
0x00, 0x69, 0x00, 0x62, 0x00, 0x72, 0x00, 0x69,
|
|
160
|
-
0x00,
|
|
161
|
-
0x2B, 0x27, 0xDC, 0x00, 0x01, 0x00, 0xBC, 0x02,
|
|
162
|
-
0x00, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x07, 0x01,
|
|
163
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x02, 0x07,
|
|
164
|
-
0x00, 0x00, 0x00, 0x43, 0x00, 0x61, 0x00, 0x6C,
|
|
165
|
-
0x00, 0x69, 0x00, 0x62, 0x00, 0x72, 0x00, 0x69,
|
|
166
|
-
0x00,
|
|
167
|
-
0x25, 0x06, 0x01, 0x00, 0x02, 0x0E, 0x00, 0x80, 0x81, 0x08, 0x00, 0x26, 0x00, 0xE4, 0x04, 0x00, 0xDB, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00,
|
|
168
|
-
0x2D, 0x44, 0x00, 0x00, 0x00, 0x00, 0x03, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x41, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
171
|
-
0x00, 0x2D, 0x44, 0x11, 0x00, 0x00, 0x00, 0x03, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x41, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
172
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
173
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
174
|
-
0x00, 0x00, 0xDC, 0x04, 0x00, 0xE5, 0x04, 0x04, 0x01, 0x00, 0x00, 0x00, 0x2E, 0x33, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
175
|
-
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
176
|
-
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE6, 0x04, 0x00, 0xF2,
|
|
177
|
-
0x04, 0x04, 0x01, 0x00, 0x00, 0x00, 0x2F, 0x10, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,
|
|
178
|
-
0x00, 0xF3, 0x04, 0x00, 0xE9, 0x04, 0x04,
|
|
179
|
-
0x04,
|
|
180
|
-
0x00, 0x00, 0x00,
|
|
181
|
-
0x2F, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,
|
|
182
|
-
0x2F, 0x10, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x01, 0x00,
|
|
183
|
-
0x2F, 0x10, 0x00, 0x00, 0xA6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x01, 0x00,
|
|
184
|
-
0x2F, 0x10, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,
|
|
185
|
-
0xEA, 0x04, 0x00, 0xEB, 0x04, 0x04, 0x01, 0x00,
|
|
186
|
-
0x00, 0x00, 0x25, 0x06, 0x01, 0x00, 0x02, 0x11, 0x00, 0x80, 0x80, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
187
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x00, 0x30, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4E,
|
|
188
|
-
0x00, 0x6F, 0x00, 0x72, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x6C, 0x00, 0x6E, 0x00, 0x79, 0x00, 0xEC, 0x04, 0x00, 0xF9, 0x03, 0x04, 0x00, 0x00,
|
|
189
|
-
0x00, 0x00, 0xFA, 0x03, 0x00, 0xFC, 0x03, 0x50, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x54, 0x00, 0x61, 0x00, 0x62, 0x00, 0x6C,
|
|
190
|
-
0x00, 0x65, 0x00, 0x53, 0x00, 0x74, 0x00, 0x79, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x4D, 0x00, 0x65, 0x00, 0x64, 0x00, 0x69, 0x00, 0x75, 0x00,
|
|
191
|
-
0x6D, 0x00, 0x32, 0x00, 0x11, 0x00, 0x00, 0x00, 0x50, 0x00, 0x69, 0x00, 0x76, 0x00, 0x6F, 0x00, 0x74, 0x00, 0x53, 0x00, 0x74, 0x00, 0x79,
|
|
192
|
-
0x00, 0x6C, 0x00, 0x65, 0x00, 0x4C, 0x00, 0x69, 0x00, 0x67, 0x00, 0x68, 0x00, 0x74, 0x00, 0x31, 0x00, 0x36, 0x00, 0xFD, 0x03, 0x00, 0x23,
|
|
193
|
-
0x04, 0x02, 0x0E, 0x00, 0x00, 0xEB, 0x08, 0x00, 0xF6, 0x08, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x53, 0x00, 0x6C, 0x00,
|
|
194
|
-
0x69, 0x00, 0x63, 0x00, 0x65, 0x00, 0x72, 0x00, 0x53, 0x00, 0x74, 0x00, 0x79, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x4C, 0x00, 0x69, 0x00, 0x67,
|
|
195
|
-
0x00, 0x68, 0x00, 0x74, 0x00, 0x31, 0x00, 0xF7, 0x08, 0x00, 0xEC, 0x08, 0x00, 0x24, 0x00, 0x23, 0x04, 0x03, 0x0F, 0x00, 0x00, 0xB0, 0x10,
|
|
196
|
-
0x00, 0xB2, 0x10, 0x32, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x54, 0x00, 0x69, 0x00, 0x6D, 0x00, 0x65, 0x00, 0x53, 0x00, 0x6C,
|
|
197
|
-
0x00, 0x69, 0x00, 0x63, 0x00, 0x65, 0x00, 0x72, 0x00, 0x53, 0x00, 0x74, 0x00, 0x79, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x4C, 0x00, 0x69, 0x00,
|
|
198
|
-
0x67, 0x00, 0x68, 0x00, 0x74, 0x00, 0x31, 0x00, 0xB3, 0x10, 0x00, 0xB1, 0x10, 0x00, 0x24, 0x00, 0x97, 0x02, 0x00
|
|
199
|
-
]);
|
|
200
|
-
this._binaryIndexBin = Buffer.from([
|
|
201
|
-
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,
|
|
202
|
-
0x02, 0x00
|
|
203
|
-
]);
|
|
204
|
-
this._rRkIntegerLowerLimit = -1 << 29;
|
|
205
|
-
this._rRkIntegerUpperLimit = (1 << 29) - 1;
|
|
206
|
-
this._autoFilterStartBytes = Buffer.from([0xA1, 0x01, 0x10]);
|
|
207
|
-
this._autoFilterEndBytes = Buffer.from([0xA2, 0x01, 0x00]);
|
|
208
|
-
this._stickHeaderA1bytes = Buffer.from([
|
|
209
|
-
0x97, 0x01, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
210
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
211
|
-
0x00, 0xF0, 0x3F, 0x01, 0x00, 0x00, 0x00, 0x00,
|
|
212
|
-
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03
|
|
213
|
-
]);
|
|
214
|
-
this._magicFilterExcel2016Fix0 = Buffer.from([0xE1, 0x02, 0x00, 0xE5, 0x02, 0x00, 0xEA, 0x02]);
|
|
215
|
-
this._magicFilterExcel2016Fix1 = Buffer.from([
|
|
216
|
-
0x27, 0x46, 0x21, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x5F,
|
|
217
|
-
0x00, 0x46, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x74, 0x00, 0x65, 0x00, 0x72, 0x00, 0x44, 0x00, 0x61,
|
|
218
|
-
0x00, 0x74, 0x00, 0x61, 0x00, 0x62, 0x00, 0x61, 0x00, 0x73, 0x00, 0x65, 0x00, 0x0F, 0x00, 0x00,
|
|
219
|
-
0x00, 0x3B, 0xFF, 0x00
|
|
220
|
-
]);
|
|
221
|
-
this._magicFilterExcel2016Fix2 = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF]);
|
|
222
|
-
}
|
|
223
|
-
_sanitizeSheetName(name) {
|
|
224
|
-
if (!name || typeof name !== 'string') {
|
|
225
|
-
return `Sheet${this.sheetCount + 1}`;
|
|
226
|
-
}
|
|
227
|
-
let sanitized = name.replace(INVALID_SHEET_NAME_CHARS, '_');
|
|
228
|
-
if (sanitized.length > 31) {
|
|
229
|
-
sanitized = sanitized.substring(0, 31);
|
|
230
|
-
}
|
|
231
|
-
if (sanitized.trim().length === 0) {
|
|
232
|
-
sanitized = `Sheet${this.sheetCount + 1}`;
|
|
233
|
-
}
|
|
234
|
-
return sanitized;
|
|
235
|
-
}
|
|
236
|
-
_registerFormat(fmtString) {
|
|
237
|
-
if (this._stFmtRecords.has(fmtString)) {
|
|
238
|
-
return this._stFmtRecords.get(fmtString).xfIndex;
|
|
239
|
-
}
|
|
240
|
-
const numfmtId = this._nextFmtId++;
|
|
241
|
-
const xfIndex = this._nextXfIdx++;
|
|
242
|
-
this._stFmtRecords.set(fmtString, { numfmtId, xfIndex });
|
|
243
|
-
return xfIndex;
|
|
244
|
-
}
|
|
245
|
-
static _buildBrtRecord(type, data) {
|
|
246
|
-
const header = XlsbWriter._encodeVlq(type);
|
|
247
|
-
header.push(...XlsbWriter._encodeVlq(data.length));
|
|
248
|
-
return Buffer.concat([Buffer.from(header), data]);
|
|
249
|
-
}
|
|
250
|
-
static _encodeVlq(value) {
|
|
251
|
-
const result = [];
|
|
252
|
-
while (value >= 0x80) {
|
|
253
|
-
result.push((value & 0x7F) | 0x80);
|
|
254
|
-
value >>>= 7;
|
|
255
|
-
}
|
|
256
|
-
result.push(value & 0x7F);
|
|
257
|
-
return result;
|
|
258
|
-
}
|
|
259
|
-
static _buildStFmtRecord(ifmt, fmtString) {
|
|
260
|
-
const cch = fmtString.length;
|
|
261
|
-
const remaining = 2 + 4 + cch * 2;
|
|
262
|
-
const data = Buffer.alloc(2 + remaining);
|
|
263
|
-
data[0] = 0x2C;
|
|
264
|
-
data[1] = remaining;
|
|
265
|
-
data.writeUInt16LE(ifmt, 2);
|
|
266
|
-
data.writeUInt32LE(cch, 4);
|
|
267
|
-
data.write(fmtString, 8, cch * 2, 'utf16le');
|
|
268
|
-
return data;
|
|
269
|
-
}
|
|
270
|
-
static _buildXfRecord(fontId, ifmt, flags, byte6Extra = 0) {
|
|
271
|
-
const data = Buffer.alloc(18);
|
|
272
|
-
data[0] = 0x2F;
|
|
273
|
-
data[1] = 16;
|
|
274
|
-
data.writeUInt16LE(fontId, 2);
|
|
275
|
-
data.writeUInt16LE(ifmt, 4);
|
|
276
|
-
data[6] = byte6Extra;
|
|
277
|
-
data[14] = 0x10;
|
|
278
|
-
data[15] = 0x10;
|
|
279
|
-
data.writeUInt16LE(flags, 16);
|
|
280
|
-
return data;
|
|
281
|
-
}
|
|
282
|
-
_buildStylesBin() {
|
|
283
|
-
if (this._stFmtRecords.size === 0) {
|
|
284
|
-
return this._stylesBin;
|
|
285
|
-
}
|
|
286
|
-
const base = this._stylesBin;
|
|
287
|
-
// Find BrtEndFonts (0xE8, 0x04, 0x00)
|
|
288
|
-
let fontEndOff = -1;
|
|
289
|
-
for (let i = 3; i < base.length - 3; i++) {
|
|
290
|
-
if (base[i] === 0xE8 && base[i + 1] === 0x04 && base[i + 2] === 0x00) {
|
|
291
|
-
fontEndOff = i;
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
// Find BrtBeginCellXFs (0xE9, 0x04)
|
|
296
|
-
let xfBeginOff = -1;
|
|
297
|
-
for (let i = fontEndOff + 3; i < base.length - 2; i++) {
|
|
298
|
-
if (base[i] === 0xE9 && base[i + 1] === 0x04) {
|
|
299
|
-
xfBeginOff = i;
|
|
300
|
-
break;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
// Find BrtEndCellXFs (0xEA, 0x04, 0x00)
|
|
304
|
-
let xfEndOff = -1;
|
|
305
|
-
for (let i = xfBeginOff; i < base.length - 3; i++) {
|
|
306
|
-
if (base[i] === 0xEA && base[i + 1] === 0x04 && base[i + 2] === 0x00) {
|
|
307
|
-
xfEndOff = i;
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
// Find BrtBeginFills (0xE3, 0x04) — start after BrtEndFonts
|
|
312
|
-
let fillBeginOff = -1;
|
|
313
|
-
for (let i = fontEndOff + 3; i < base.length - 2; i++) {
|
|
314
|
-
if (base[i] === 0xE3 && base[i + 1] === 0x04) {
|
|
315
|
-
fillBeginOff = i;
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
const totalFmt = 2 + this._stFmtRecords.size;
|
|
320
|
-
const totalXf = 4 + this._stFmtRecords.size;
|
|
321
|
-
const parts = [];
|
|
322
|
-
// 1. BrtBeginStyleSheet
|
|
323
|
-
parts.push(base.subarray(0, 3));
|
|
324
|
-
// 2. NEW BrtFmt: VLQ(0x0267) + VLQ(4) + count(2 LE) + pad(2)
|
|
325
|
-
const fmtHeader = Buffer.alloc(4);
|
|
326
|
-
fmtHeader.writeUInt16LE(totalFmt, 0);
|
|
327
|
-
parts.push(XlsbWriter._buildBrtRecord(0x0267, fmtHeader));
|
|
328
|
-
// 3. BrtNumFmt records: 2 base + custom (ALWAYS add base formats)
|
|
329
|
-
parts.push(XlsbWriter._buildStFmtRecord(164, 'yyyy\\-mm\\-dd\\ hh:mm'));
|
|
330
|
-
parts.push(XlsbWriter._buildStFmtRecord(166, 'yyyy\\-mm\\-dd'));
|
|
331
|
-
for (const [fmtString, st] of this._stFmtRecords) {
|
|
332
|
-
parts.push(XlsbWriter._buildStFmtRecord(st.numfmtId, fmtString));
|
|
333
|
-
}
|
|
334
|
-
// 4. BrtEndFonts
|
|
335
|
-
parts.push(XlsbWriter._buildBrtRecord(0x0268, Buffer.alloc(0)));
|
|
336
|
-
// 5. Copy fills+borders+BrtFont+cellStyleXFs from template
|
|
337
|
-
parts.push(base.subarray(fillBeginOff, xfBeginOff));
|
|
338
|
-
// 7. NEW BrtBeginCellXFs
|
|
339
|
-
const xfHeader = Buffer.alloc(4);
|
|
340
|
-
xfHeader.writeUInt16LE(totalXf, 0);
|
|
341
|
-
parts.push(XlsbWriter._buildBrtRecord(0x0269, xfHeader));
|
|
342
|
-
// 8. Base XF records
|
|
343
|
-
parts.push(XlsbWriter._buildXfRecord(0, 0, 0x0000));
|
|
344
|
-
parts.push(XlsbWriter._buildXfRecord(0, 164, 0x0001));
|
|
345
|
-
parts.push(XlsbWriter._buildXfRecord(0, 166, 0x0001));
|
|
346
|
-
parts.push(XlsbWriter._buildXfRecord(1, 0, 0x0000, 1));
|
|
347
|
-
// 9. Custom XF records
|
|
348
|
-
const sortedXf = [...this._stFmtRecords.entries()].sort((a, b) => a[1].xfIndex - b[1].xfIndex);
|
|
349
|
-
for (const [, st] of sortedXf) {
|
|
350
|
-
parts.push(XlsbWriter._buildXfRecord(0, st.numfmtId, 0x0001));
|
|
351
|
-
}
|
|
352
|
-
// 10. BrtEndCellXFs
|
|
353
|
-
parts.push(XlsbWriter._buildBrtRecord(0x026A, Buffer.alloc(0)));
|
|
354
|
-
// 11. Copy remaining template
|
|
355
|
-
parts.push(base.subarray(xfEndOff + 3));
|
|
356
|
-
return Buffer.concat(parts);
|
|
357
|
-
}
|
|
358
|
-
addSheet(sheetName, hidden = false) {
|
|
359
|
-
const sanitizedName = this._sanitizeSheetName(sheetName);
|
|
360
|
-
this.sheetCount++;
|
|
361
|
-
this.sheetList.push({
|
|
362
|
-
name: sanitizedName,
|
|
363
|
-
pathInArchive: `xl/worksheets/sheet${this.sheetCount}.bin`,
|
|
364
|
-
hidden: hidden,
|
|
365
|
-
nameInArchive: `sheet${this.sheetCount}.bin`,
|
|
366
|
-
sheetId: this.sheetCount,
|
|
367
|
-
filterHeaderRange: null
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Start a new sheet in streaming mode. Call writeRow() for each row, then endSheet() when done.
|
|
372
|
-
* @param sheetName Name of the sheet
|
|
373
|
-
* @param columnCount Number of columns in the sheet
|
|
374
|
-
* @param headers Optional header row
|
|
375
|
-
* @param options Optional settings (hidden, doAutofilter)
|
|
376
|
-
*/
|
|
377
|
-
startSheet(sheetName, columnCount, headers, options = {}) {
|
|
378
|
-
if (this.isStreaming) {
|
|
379
|
-
throw new Error('Already in streaming mode. Call endSheet() first.');
|
|
380
|
-
}
|
|
381
|
-
const { hidden = false, doAutofilter = true, sampleRows } = options;
|
|
382
|
-
// Add sheet metadata
|
|
383
|
-
this.addSheet(sheetName, hidden);
|
|
384
|
-
// Initialize streaming state
|
|
385
|
-
this.isStreaming = true;
|
|
386
|
-
this.currentSheetBuffer = new BigBuffer_1.BigBuffer();
|
|
387
|
-
this.currentSheetRowNum = 0;
|
|
388
|
-
this.currentSheetStartCol = 0;
|
|
389
|
-
this.currentSheetEndCol = columnCount;
|
|
390
|
-
this.currentSheetDoAutofilter = doAutofilter && headers !== undefined;
|
|
391
|
-
const bigBuf = this.currentSheetBuffer;
|
|
392
|
-
// Initialize column widths
|
|
393
|
-
this.colWidths = new Array(columnCount).fill(-1.0);
|
|
394
|
-
if (headers) {
|
|
395
|
-
for (let i = 0; i < columnCount; i++) {
|
|
396
|
-
const len = headers[i] ? headers[i].length + 1 : 0;
|
|
397
|
-
let width = 1.25 * len + 2;
|
|
398
|
-
if (width > 80)
|
|
399
|
-
width = 80;
|
|
400
|
-
if (this.colWidths[i] < width)
|
|
401
|
-
this.colWidths[i] = width;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
if (sampleRows) {
|
|
405
|
-
for (let r = 0; r < Math.min(sampleRows.length, 100); r++) {
|
|
406
|
-
const row = sampleRows[r];
|
|
407
|
-
for (let c = 0; c < row.length; c++) {
|
|
408
|
-
const raw = row[c];
|
|
409
|
-
if (raw === null || raw === undefined)
|
|
410
|
-
continue;
|
|
411
|
-
const val = (0, Formats_1.isFormattedCell)(raw) ? raw.value : raw;
|
|
412
|
-
const len = val instanceof Date ? 20 : val.toString().length + 1;
|
|
413
|
-
let width = 1.25 * len + 2;
|
|
414
|
-
if (width > 80)
|
|
415
|
-
width = 80;
|
|
416
|
-
if (this.colWidths[c] < width)
|
|
417
|
-
this.colWidths[c] = width;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
// Write sheet header
|
|
422
|
-
const sheetHeader = Buffer.from(this._sheet1Bytes);
|
|
423
|
-
sheetHeader.writeInt32LE(this.currentSheetStartCol, 40);
|
|
424
|
-
sheetHeader.writeInt32LE(this.currentSheetEndCol, 44);
|
|
425
|
-
if (this.sheetCount !== 1) {
|
|
426
|
-
sheetHeader[54] = 0x9C;
|
|
427
|
-
}
|
|
428
|
-
bigBuf.write(sheetHeader.subarray(0, 84));
|
|
429
|
-
// Write sticky header if headers are present
|
|
430
|
-
if (headers) {
|
|
431
|
-
bigBuf.write(this._stickHeaderA1bytes);
|
|
432
|
-
}
|
|
433
|
-
bigBuf.write(sheetHeader.subarray(84, 159));
|
|
434
|
-
// Write column definitions
|
|
435
|
-
bigBuf.writeByte(134);
|
|
436
|
-
bigBuf.writeByte(3);
|
|
437
|
-
for (let i = this.currentSheetStartCol; i < this.currentSheetEndCol; i++) {
|
|
438
|
-
bigBuf.writeByte(0);
|
|
439
|
-
bigBuf.writeByte(60);
|
|
440
|
-
bigBuf.writeByte(18);
|
|
441
|
-
bigBuf.writeInt32LE(i);
|
|
442
|
-
bigBuf.writeInt32LE(i);
|
|
443
|
-
const width = this.colWidths[i] > 0 ? Math.floor(this.colWidths[i]) : 10;
|
|
444
|
-
bigBuf.writeByte(0);
|
|
445
|
-
bigBuf.writeByte(Math.max(0, Math.min(255, width)));
|
|
446
|
-
bigBuf.writeByte(0);
|
|
447
|
-
bigBuf.writeByte(0);
|
|
448
|
-
bigBuf.writeByte(0);
|
|
449
|
-
bigBuf.writeByte(0);
|
|
450
|
-
bigBuf.writeByte(0);
|
|
451
|
-
bigBuf.writeByte(0);
|
|
452
|
-
bigBuf.writeByte(2);
|
|
453
|
-
}
|
|
454
|
-
bigBuf.writeByte(0);
|
|
455
|
-
bigBuf.writeByte(135);
|
|
456
|
-
bigBuf.writeByte(3);
|
|
457
|
-
bigBuf.writeByte(0);
|
|
458
|
-
bigBuf.write(sheetHeader.subarray(159, 175));
|
|
459
|
-
bigBuf.write(Buffer.from([38, 0]));
|
|
460
|
-
// Write header row if provided
|
|
461
|
-
if (headers) {
|
|
462
|
-
this.createRowHeader(bigBuf, this.currentSheetRowNum, this.currentSheetStartCol, this.currentSheetEndCol);
|
|
463
|
-
for (let c = 0; c < headers.length; c++) {
|
|
464
|
-
this.writeString(bigBuf, headers[c], c, true);
|
|
465
|
-
}
|
|
466
|
-
this.currentSheetRowNum++;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Write a single row in streaming mode. Must be called between startSheet() and endSheet().
|
|
471
|
-
* @param row Array of cell values
|
|
472
|
-
*/
|
|
473
|
-
writeRow(row) {
|
|
474
|
-
if (!this.isStreaming || !this.currentSheetBuffer) {
|
|
475
|
-
throw new Error('Not in streaming mode. Call startSheet() first.');
|
|
476
|
-
}
|
|
477
|
-
if (row.length !== this.currentSheetEndCol - this.currentSheetStartCol) {
|
|
478
|
-
throw new Error(`Row length mismatch. Expected ${this.currentSheetEndCol - this.currentSheetStartCol} columns, got ${row.length}`);
|
|
479
|
-
}
|
|
480
|
-
const bigBuf = this.currentSheetBuffer;
|
|
481
|
-
// Write row header
|
|
482
|
-
this.createRowHeader(bigBuf, this.currentSheetRowNum, this.currentSheetStartCol, this.currentSheetEndCol);
|
|
483
|
-
// Write each cell
|
|
484
|
-
for (let c = 0; c < row.length; c++) {
|
|
485
|
-
const raw = row[c];
|
|
486
|
-
if (raw === null || raw === undefined)
|
|
487
|
-
continue;
|
|
488
|
-
const fmtString = (0, Formats_1.getFormat)(raw);
|
|
489
|
-
const val = fmtString !== null ? (0, Formats_1.unwrapCell)(raw) : raw;
|
|
490
|
-
const styleNum = fmtString !== null ? this._registerFormat(fmtString) : 0;
|
|
491
|
-
if (typeof val === 'number') {
|
|
492
|
-
if (Number.isInteger(val)) {
|
|
493
|
-
if (val >= this._rRkIntegerLowerLimit && val <= this._rRkIntegerUpperLimit) {
|
|
494
|
-
this.writeRkNumberInteger(bigBuf, val, c, styleNum);
|
|
495
|
-
}
|
|
496
|
-
else {
|
|
497
|
-
this.writeDouble(bigBuf, val, c, styleNum);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
else {
|
|
501
|
-
this.writeDouble(bigBuf, val, c, styleNum);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
else if (typeof val === 'bigint') {
|
|
505
|
-
this.writeString(bigBuf, val.toString(), c);
|
|
506
|
-
}
|
|
507
|
-
else if (typeof val === 'boolean') {
|
|
508
|
-
this.writeBool(bigBuf, val, c);
|
|
509
|
-
}
|
|
510
|
-
else if (val instanceof Date) {
|
|
511
|
-
const oaDate = (val.getTime() - this._oaEpoch) / 86400000;
|
|
512
|
-
this.writeDouble(bigBuf, oaDate, c, fmtString !== null ? styleNum : 1);
|
|
513
|
-
}
|
|
514
|
-
else {
|
|
515
|
-
this.writeString(bigBuf, val.toString(), c, false, fmtString !== null ? styleNum : undefined);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
this.currentSheetRowNum++;
|
|
519
|
-
}
|
|
520
|
-
/**
|
|
521
|
-
* Finalize the current streaming sheet and add it to the archive.
|
|
522
|
-
* Must be called after startSheet() and writeRow() calls.
|
|
523
|
-
*/
|
|
524
|
-
endSheet() {
|
|
525
|
-
if (!this.isStreaming || !this.currentSheetBuffer) {
|
|
526
|
-
throw new Error('Not in streaming mode. Call startSheet() first.');
|
|
527
|
-
}
|
|
528
|
-
const bigBuf = this.currentSheetBuffer;
|
|
529
|
-
const sheetHeader = Buffer.from(this._sheet1Bytes);
|
|
530
|
-
// Write sheet footer sections
|
|
531
|
-
bigBuf.write(sheetHeader.subarray(218, 290));
|
|
532
|
-
// Write autofilter if enabled
|
|
533
|
-
if (this.currentSheetDoAutofilter) {
|
|
534
|
-
this._autofilterIsOn = true;
|
|
535
|
-
const endRow = this.currentSheetRowNum;
|
|
536
|
-
bigBuf.write(this._autoFilterStartBytes);
|
|
537
|
-
const rowBuf = Buffer.alloc(8);
|
|
538
|
-
rowBuf.writeInt32LE(0, 0);
|
|
539
|
-
rowBuf.writeInt32LE(endRow - 1, 4);
|
|
540
|
-
bigBuf.write(rowBuf);
|
|
541
|
-
const colBuf = Buffer.alloc(8);
|
|
542
|
-
colBuf.writeInt32LE(this.currentSheetStartCol, 0);
|
|
543
|
-
colBuf.writeInt32LE(this.currentSheetEndCol - 1, 4);
|
|
544
|
-
bigBuf.write(colBuf);
|
|
545
|
-
bigBuf.write(this._autoFilterEndBytes);
|
|
546
|
-
// Update sheet metadata with filter info
|
|
547
|
-
const sheet = this.sheetList[this.sheetCount - 1];
|
|
548
|
-
sheet.filterData = {
|
|
549
|
-
startRow: 0,
|
|
550
|
-
endRow: this.currentSheetRowNum - 1,
|
|
551
|
-
startColumn: this.currentSheetStartCol,
|
|
552
|
-
endColumn: this.currentSheetEndCol - 1
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
// Write final sheet footer
|
|
556
|
-
bigBuf.write(sheetHeader.subarray(290));
|
|
557
|
-
// Append to archive as a stream
|
|
558
|
-
this.archive.append(stream_1.Readable.from(bigBuf.getChunks()), {
|
|
559
|
-
name: this.sheetList[this.sheetCount - 1].pathInArchive
|
|
560
|
-
});
|
|
561
|
-
// Reset streaming state
|
|
562
|
-
this.isStreaming = false;
|
|
563
|
-
this.currentSheetBuffer = null;
|
|
564
|
-
this.currentSheetRowNum = 0;
|
|
565
|
-
this.currentSheetStartCol = 0;
|
|
566
|
-
this.currentSheetEndCol = 0;
|
|
567
|
-
this.currentSheetDoAutofilter = false;
|
|
568
|
-
}
|
|
569
|
-
writeSheet(rows, headers = null, doAutofilter = true) {
|
|
570
|
-
const bigBuf = new BigBuffer_1.BigBuffer();
|
|
571
|
-
let columnCount = 0;
|
|
572
|
-
if (rows.length > 0) {
|
|
573
|
-
columnCount = rows[0].length;
|
|
574
|
-
}
|
|
575
|
-
else if (headers) {
|
|
576
|
-
columnCount = headers.length;
|
|
577
|
-
}
|
|
578
|
-
this.colWidths = new Array(columnCount).fill(-1.0);
|
|
579
|
-
if (headers) {
|
|
580
|
-
for (let i = 0; i < columnCount; i++) {
|
|
581
|
-
const len = headers[i] ? headers[i].length + 1 : 0;
|
|
582
|
-
let width = 1.25 * len + 2;
|
|
583
|
-
if (width > 80)
|
|
584
|
-
width = 80;
|
|
585
|
-
if (this.colWidths[i] < width)
|
|
586
|
-
this.colWidths[i] = width;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
for (let r = 0; r < Math.min(rows.length, 100); r++) {
|
|
590
|
-
const row = rows[r];
|
|
591
|
-
for (let c = 0; c < row.length; c++) {
|
|
592
|
-
const raw = row[c];
|
|
593
|
-
if (raw === null || raw === undefined)
|
|
594
|
-
continue;
|
|
595
|
-
const val = (0, Formats_1.isFormattedCell)(raw) ? raw.value : raw;
|
|
596
|
-
const len = val instanceof Date ? 20 : val.toString().length + 1;
|
|
597
|
-
let width = 1.25 * len + 2;
|
|
598
|
-
if (width > 80)
|
|
599
|
-
width = 80;
|
|
600
|
-
if (this.colWidths[c] < width)
|
|
601
|
-
this.colWidths[c] = width;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
const sheetHeader = Buffer.from(this._sheet1Bytes);
|
|
605
|
-
const startCol = 0;
|
|
606
|
-
const endCol = columnCount;
|
|
607
|
-
sheetHeader.writeInt32LE(startCol, 40);
|
|
608
|
-
sheetHeader.writeInt32LE(endCol, 44);
|
|
609
|
-
if (this.sheetCount !== 1) {
|
|
610
|
-
sheetHeader[54] = 0x9C;
|
|
611
|
-
}
|
|
612
|
-
bigBuf.write(sheetHeader.subarray(0, 84));
|
|
613
|
-
if (headers) {
|
|
614
|
-
bigBuf.write(this._stickHeaderA1bytes);
|
|
615
|
-
}
|
|
616
|
-
bigBuf.write(sheetHeader.subarray(84, 159));
|
|
617
|
-
bigBuf.writeByte(134);
|
|
618
|
-
bigBuf.writeByte(3);
|
|
619
|
-
for (let i = startCol; i < endCol; i++) {
|
|
620
|
-
bigBuf.writeByte(0);
|
|
621
|
-
bigBuf.writeByte(60);
|
|
622
|
-
bigBuf.writeByte(18);
|
|
623
|
-
bigBuf.writeInt32LE(i);
|
|
624
|
-
bigBuf.writeInt32LE(i);
|
|
625
|
-
const width = this.colWidths[i] > 0 ? Math.floor(this.colWidths[i]) : 10;
|
|
626
|
-
bigBuf.writeByte(0);
|
|
627
|
-
bigBuf.writeByte(Math.max(0, Math.min(255, width)));
|
|
628
|
-
bigBuf.writeByte(0);
|
|
629
|
-
bigBuf.writeByte(0);
|
|
630
|
-
bigBuf.writeByte(0);
|
|
631
|
-
bigBuf.writeByte(0);
|
|
632
|
-
bigBuf.writeByte(0);
|
|
633
|
-
bigBuf.writeByte(0);
|
|
634
|
-
bigBuf.writeByte(2);
|
|
635
|
-
}
|
|
636
|
-
bigBuf.writeByte(0);
|
|
637
|
-
bigBuf.writeByte(135);
|
|
638
|
-
bigBuf.writeByte(3);
|
|
639
|
-
bigBuf.writeByte(0);
|
|
640
|
-
bigBuf.write(sheetHeader.subarray(159, 175));
|
|
641
|
-
bigBuf.write(Buffer.from([38, 0]));
|
|
642
|
-
let rowNum = 0;
|
|
643
|
-
if (headers) {
|
|
644
|
-
this.createRowHeader(bigBuf, rowNum, startCol, endCol);
|
|
645
|
-
for (let c = 0; c < headers.length; c++) {
|
|
646
|
-
this.writeString(bigBuf, headers[c], c, true);
|
|
647
|
-
}
|
|
648
|
-
rowNum++;
|
|
649
|
-
}
|
|
650
|
-
for (let r = 0; r < rows.length; r++) {
|
|
651
|
-
this.createRowHeader(bigBuf, rowNum, startCol, endCol);
|
|
652
|
-
const row = rows[r];
|
|
653
|
-
for (let c = 0; c < row.length; c++) {
|
|
654
|
-
const raw = row[c];
|
|
655
|
-
if (raw === null || raw === undefined)
|
|
656
|
-
continue;
|
|
657
|
-
const fmtString = (0, Formats_1.getFormat)(raw);
|
|
658
|
-
const val = fmtString !== null ? (0, Formats_1.unwrapCell)(raw) : raw;
|
|
659
|
-
const styleNum = fmtString !== null ? this._registerFormat(fmtString) : 0;
|
|
660
|
-
if (typeof val === 'number') {
|
|
661
|
-
if (Number.isInteger(val)) {
|
|
662
|
-
if (val >= this._rRkIntegerLowerLimit && val <= this._rRkIntegerUpperLimit) {
|
|
663
|
-
this.writeRkNumberInteger(bigBuf, val, c, styleNum);
|
|
664
|
-
}
|
|
665
|
-
else {
|
|
666
|
-
this.writeDouble(bigBuf, val, c, styleNum);
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
else {
|
|
670
|
-
this.writeDouble(bigBuf, val, c, styleNum);
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
else if (typeof val === 'bigint') {
|
|
674
|
-
this.writeString(bigBuf, val.toString(), c);
|
|
675
|
-
}
|
|
676
|
-
else if (typeof val === 'boolean') {
|
|
677
|
-
this.writeBool(bigBuf, val, c);
|
|
678
|
-
}
|
|
679
|
-
else if (val instanceof Date) {
|
|
680
|
-
const oaDate = (val.getTime() - this._oaEpoch) / 86400000;
|
|
681
|
-
this.writeDouble(bigBuf, oaDate, c, fmtString !== null ? styleNum : 1);
|
|
682
|
-
}
|
|
683
|
-
else {
|
|
684
|
-
this.writeString(bigBuf, val.toString(), c, false, fmtString !== null ? styleNum : undefined);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
rowNum++;
|
|
688
|
-
}
|
|
689
|
-
bigBuf.write(sheetHeader.subarray(218, 290));
|
|
690
|
-
if (doAutofilter && headers) {
|
|
691
|
-
this._autofilterIsOn = true;
|
|
692
|
-
const endRow = rows.length + 1;
|
|
693
|
-
bigBuf.write(this._autoFilterStartBytes);
|
|
694
|
-
const rowBuf = Buffer.alloc(8);
|
|
695
|
-
rowBuf.writeInt32LE(0, 0);
|
|
696
|
-
rowBuf.writeInt32LE(endRow - 1, 4);
|
|
697
|
-
bigBuf.write(rowBuf);
|
|
698
|
-
const colBuf = Buffer.alloc(8);
|
|
699
|
-
colBuf.writeInt32LE(startCol, 0);
|
|
700
|
-
colBuf.writeInt32LE(endCol - 1, 4);
|
|
701
|
-
bigBuf.write(colBuf);
|
|
702
|
-
bigBuf.write(this._autoFilterEndBytes);
|
|
703
|
-
const sheet = this.sheetList[this.sheetCount - 1];
|
|
704
|
-
sheet.filterData = {
|
|
705
|
-
startRow: 0,
|
|
706
|
-
endRow: rows.length,
|
|
707
|
-
startColumn: startCol,
|
|
708
|
-
endColumn: endCol - 1
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
bigBuf.write(sheetHeader.subarray(290));
|
|
712
|
-
this.archive.append(stream_1.Readable.from(bigBuf.getChunks()), { name: this.sheetList[this.sheetCount - 1].pathInArchive });
|
|
713
|
-
}
|
|
714
|
-
createRowHeader(bigBuf, rowNumber, startCol, endCol) {
|
|
715
|
-
bigBuf.ensureCapacity(27);
|
|
716
|
-
bigBuf.writeUnsafeByte(0);
|
|
717
|
-
bigBuf.writeUnsafeByte(25);
|
|
718
|
-
bigBuf.writeUnsafeInt32LE(rowNumber);
|
|
719
|
-
bigBuf.writeUnsafeInt32LE(0);
|
|
720
|
-
bigBuf.writeUnsafeByte(44);
|
|
721
|
-
bigBuf.writeUnsafeByte(1);
|
|
722
|
-
bigBuf.writeUnsafeByte(0);
|
|
723
|
-
bigBuf.writeUnsafeByte(0);
|
|
724
|
-
bigBuf.writeUnsafeByte(0);
|
|
725
|
-
bigBuf.writeUnsafeByte(1);
|
|
726
|
-
bigBuf.writeUnsafeByte(0);
|
|
727
|
-
bigBuf.writeUnsafeByte(0);
|
|
728
|
-
bigBuf.writeUnsafeByte(0);
|
|
729
|
-
bigBuf.writeUnsafeInt32LE(startCol);
|
|
730
|
-
bigBuf.writeUnsafeInt32LE(endCol);
|
|
731
|
-
}
|
|
732
|
-
writeRkNumberInteger(bigBuf, val, colNum, styleNum = 0) {
|
|
733
|
-
bigBuf.ensureCapacity(14);
|
|
734
|
-
bigBuf.writeUnsafeByte(2);
|
|
735
|
-
bigBuf.writeUnsafeByte(12);
|
|
736
|
-
bigBuf.writeUnsafeInt32LE(colNum);
|
|
737
|
-
bigBuf.writeUnsafeByte(styleNum);
|
|
738
|
-
bigBuf.writeUnsafeByte(0);
|
|
739
|
-
bigBuf.writeUnsafeByte(0);
|
|
740
|
-
bigBuf.writeUnsafeByte(0);
|
|
741
|
-
const rkVal = (val << 2) | 2;
|
|
742
|
-
bigBuf.writeUnsafeInt32LE(rkVal);
|
|
743
|
-
}
|
|
744
|
-
writeDouble(bigBuf, val, colNum, styleNum = 0) {
|
|
745
|
-
bigBuf.ensureCapacity(18);
|
|
746
|
-
bigBuf.writeUnsafeByte(5);
|
|
747
|
-
bigBuf.writeUnsafeByte(16);
|
|
748
|
-
bigBuf.writeUnsafeInt32LE(colNum);
|
|
749
|
-
bigBuf.writeUnsafeByte(styleNum);
|
|
750
|
-
bigBuf.writeUnsafeByte(0);
|
|
751
|
-
bigBuf.writeUnsafeByte(0);
|
|
752
|
-
bigBuf.writeUnsafeByte(0);
|
|
753
|
-
bigBuf.writeUnsafeDoubleLE(val);
|
|
754
|
-
}
|
|
755
|
-
writeBool(bigBuf, val, colNum) {
|
|
756
|
-
bigBuf.ensureCapacity(13);
|
|
757
|
-
bigBuf.writeUnsafeByte(0x04);
|
|
758
|
-
bigBuf.writeUnsafeByte(9);
|
|
759
|
-
bigBuf.writeUnsafeInt32LE(colNum);
|
|
760
|
-
bigBuf.writeUnsafeInt32LE(0);
|
|
761
|
-
bigBuf.writeUnsafeByte(val ? 1 : 0);
|
|
762
|
-
}
|
|
763
|
-
writeDateTime(bigBuf, date, colNum) {
|
|
764
|
-
// Use UTC time to avoid timezone conversion issues
|
|
765
|
-
const oaDate = (date.getTime() - this._oaEpoch) / 86400000;
|
|
766
|
-
this.writeDouble(bigBuf, oaDate, colNum, 1);
|
|
767
|
-
}
|
|
768
|
-
_getDateWidth(_date) {
|
|
769
|
-
return 19; // "YYYY-MM-DD HH:MM:SS" ≈ 19 chars
|
|
770
|
-
}
|
|
771
|
-
writeString(bigBuf, val, colNum, bolded = false, styleOverride) {
|
|
772
|
-
let index;
|
|
773
|
-
if (this.sstDic.has(val)) {
|
|
774
|
-
index = this.sstDic.get(val);
|
|
775
|
-
}
|
|
776
|
-
else {
|
|
777
|
-
index = this.sstCntUnique;
|
|
778
|
-
this.sstDic.set(val, index);
|
|
779
|
-
this.sstCntUnique++;
|
|
780
|
-
}
|
|
781
|
-
this.sstCntAll++;
|
|
782
|
-
const styleNum = styleOverride !== undefined ? styleOverride : (bolded ? 3 : 0);
|
|
783
|
-
bigBuf.ensureCapacity(17);
|
|
784
|
-
bigBuf.writeUnsafeByte(7);
|
|
785
|
-
bigBuf.writeUnsafeByte(12);
|
|
786
|
-
bigBuf.writeUnsafeInt32LE(colNum);
|
|
787
|
-
bigBuf.writeUnsafeByte(styleNum);
|
|
788
|
-
bigBuf.writeUnsafeByte(0);
|
|
789
|
-
bigBuf.writeUnsafeByte(0);
|
|
790
|
-
bigBuf.writeUnsafeByte(0);
|
|
791
|
-
bigBuf.writeUnsafeInt32LE(index);
|
|
792
|
-
}
|
|
793
|
-
saveSst() {
|
|
794
|
-
const bigBuf = new BigBuffer_1.BigBuffer();
|
|
795
|
-
bigBuf.writeByte(159);
|
|
796
|
-
bigBuf.writeByte(1);
|
|
797
|
-
bigBuf.writeByte(8);
|
|
798
|
-
bigBuf.writeInt32LE(this.sstCntUnique);
|
|
799
|
-
bigBuf.writeInt32LE(this.sstCntAll);
|
|
800
|
-
for (const [txt] of this.sstDic) {
|
|
801
|
-
const txtLen = txt.length;
|
|
802
|
-
bigBuf.writeByte(19);
|
|
803
|
-
const recLen = 5 + 2 * txtLen;
|
|
804
|
-
if (recLen >= 128) {
|
|
805
|
-
bigBuf.writeByte(128 + (recLen % 128));
|
|
806
|
-
const tmp = recLen >> 7;
|
|
807
|
-
if (tmp >= 256) {
|
|
808
|
-
bigBuf.writeByte(128 + (tmp % 128));
|
|
809
|
-
}
|
|
810
|
-
else {
|
|
811
|
-
bigBuf.writeByte(tmp);
|
|
812
|
-
}
|
|
813
|
-
bigBuf.writeByte(recLen >> 14);
|
|
814
|
-
if ((recLen >> 14) > 0) {
|
|
815
|
-
bigBuf.writeByte(0);
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
else {
|
|
819
|
-
bigBuf.writeByte(recLen & 0xFF);
|
|
820
|
-
bigBuf.writeByte((recLen >> 8) & 0xFF);
|
|
821
|
-
}
|
|
822
|
-
bigBuf.writeInt32LE(txtLen);
|
|
823
|
-
bigBuf.writeUtf16LE(txt);
|
|
824
|
-
}
|
|
825
|
-
bigBuf.writeByte(160);
|
|
826
|
-
bigBuf.writeByte(1);
|
|
827
|
-
bigBuf.writeByte(0);
|
|
828
|
-
this.archive.append(stream_1.Readable.from(bigBuf.getChunks()), { name: 'xl/sharedStrings.bin' });
|
|
829
|
-
}
|
|
830
|
-
_writeFilterDefinedName(wbBuffers, sheet, sheetNum) {
|
|
831
|
-
const filterData = sheet.filterData;
|
|
832
|
-
const sheetIndex = sheet.sheetId - 1;
|
|
833
|
-
const fix1 = Buffer.alloc(this._magicFilterExcel2016Fix1.length);
|
|
834
|
-
this._magicFilterExcel2016Fix1.copy(fix1);
|
|
835
|
-
const lastIdx = this._magicFilterExcel2016Fix1.length - 2;
|
|
836
|
-
fix1[7] = sheetIndex;
|
|
837
|
-
fix1[lastIdx] = sheetNum;
|
|
838
|
-
wbBuffers.push(fix1);
|
|
839
|
-
const rowBuf = Buffer.alloc(8);
|
|
840
|
-
rowBuf.writeInt32LE(filterData.startRow, 0);
|
|
841
|
-
rowBuf.writeInt32LE(filterData.endRow, 4);
|
|
842
|
-
wbBuffers.push(rowBuf);
|
|
843
|
-
const colBuf = Buffer.alloc(4);
|
|
844
|
-
colBuf.writeInt16LE(filterData.startColumn, 0);
|
|
845
|
-
colBuf.writeInt16LE(filterData.endColumn, 2);
|
|
846
|
-
wbBuffers.push(colBuf);
|
|
847
|
-
wbBuffers.push(this._magicFilterExcel2016Fix2);
|
|
848
|
-
}
|
|
849
|
-
finalize() {
|
|
850
|
-
return new Promise((resolve, reject) => {
|
|
851
|
-
try {
|
|
852
|
-
this.saveSst();
|
|
853
|
-
this.archive.append(this._buildStylesBin(), { name: 'xl/styles.bin' });
|
|
854
|
-
const wbBuffers = [];
|
|
855
|
-
wbBuffers.push(this._workbookBinStart);
|
|
856
|
-
for (const sheet of this.sheetList) {
|
|
857
|
-
const rId = `rId${sheet.sheetId}`;
|
|
858
|
-
const recLen = 4 + 12 + sheet.name.length * 2 + rId.length * 2;
|
|
859
|
-
const buf = Buffer.alloc(3 + recLen);
|
|
860
|
-
buf[0] = 156;
|
|
861
|
-
buf[1] = 1;
|
|
862
|
-
buf[2] = recLen;
|
|
863
|
-
let pos = 3;
|
|
864
|
-
buf.writeInt32LE(sheet.hidden ? 1 : 0, pos);
|
|
865
|
-
pos += 4;
|
|
866
|
-
buf.writeInt32LE(sheet.sheetId, pos);
|
|
867
|
-
pos += 4;
|
|
868
|
-
buf.writeInt32LE(rId.length, pos);
|
|
869
|
-
pos += 4;
|
|
870
|
-
for (let i = 0; i < rId.length; i++) {
|
|
871
|
-
const c = rId.charCodeAt(i);
|
|
872
|
-
buf[pos++] = c & 0xFF;
|
|
873
|
-
buf[pos++] = (c >> 8) & 0xFF;
|
|
874
|
-
}
|
|
875
|
-
buf.writeInt32LE(sheet.name.length, pos);
|
|
876
|
-
pos += 4;
|
|
877
|
-
for (let i = 0; i < sheet.name.length; i++) {
|
|
878
|
-
const c = sheet.name.charCodeAt(i);
|
|
879
|
-
buf[pos++] = c & 0xFF;
|
|
880
|
-
buf[pos++] = (c >> 8) & 0xFF;
|
|
881
|
-
}
|
|
882
|
-
wbBuffers.push(buf);
|
|
883
|
-
}
|
|
884
|
-
wbBuffers.push(this._workbookBinMiddle);
|
|
885
|
-
if (this._autofilterIsOn) {
|
|
886
|
-
const filteredSheets = this.sheetList.filter(s => s.filterData);
|
|
887
|
-
const cnt = filteredSheets.length;
|
|
888
|
-
if (cnt > 0) {
|
|
889
|
-
wbBuffers.push(this._magicFilterExcel2016Fix0);
|
|
890
|
-
const firstByte = cnt <= 20
|
|
891
|
-
? 0x10 + (cnt - 1) * 0x0C
|
|
892
|
-
: 0x80 + (cnt - 21) * 0x0C;
|
|
893
|
-
const countBuf = cnt <= 10
|
|
894
|
-
? Buffer.from([firstByte, cnt, 0x00, 0x00, 0x00])
|
|
895
|
-
: Buffer.from([firstByte, Math.floor((cnt - 1) / 10), cnt, 0x00, 0x00, 0x00]);
|
|
896
|
-
wbBuffers.push(countBuf);
|
|
897
|
-
for (let nm = 0; nm < cnt; nm++) {
|
|
898
|
-
const sheetIndex = filteredSheets[nm].sheetId - 1;
|
|
899
|
-
const idxBuf = Buffer.alloc(12);
|
|
900
|
-
idxBuf.writeInt32LE(0, 0);
|
|
901
|
-
idxBuf[4] = sheetIndex;
|
|
902
|
-
idxBuf[8] = sheetIndex;
|
|
903
|
-
wbBuffers.push(idxBuf);
|
|
904
|
-
}
|
|
905
|
-
wbBuffers.push(Buffer.from([0xE2, 0x02, 0x00]));
|
|
906
|
-
for (let sheetNum = 0; sheetNum < cnt; sheetNum++) {
|
|
907
|
-
const sheet = filteredSheets[sheetNum];
|
|
908
|
-
this._writeFilterDefinedName(wbBuffers, sheet, sheetNum);
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
wbBuffers.push(this._workbookBinEnd);
|
|
913
|
-
this.archive.append(Buffer.concat(wbBuffers), { name: 'xl/workbook.bin' });
|
|
914
|
-
for (const sheet of this.sheetList) {
|
|
915
|
-
this.archive.append(this._binaryIndexBin, { name: `xl/worksheets/binaryIndex${sheet.sheetId}.bin` });
|
|
916
|
-
}
|
|
917
|
-
let contentTypes = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
918
|
-
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
|
919
|
-
<Default Extension="bin" ContentType="application/vnd.ms-excel.sheet.binary.macroEnabled.main"/>
|
|
920
|
-
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
|
|
921
|
-
<Default Extension="xml" ContentType="application/xml"/>`;
|
|
922
|
-
for (const sheet of this.sheetList) {
|
|
923
|
-
contentTypes += `<Override PartName="/${sheet.pathInArchive}" ContentType="application/vnd.ms-excel.worksheet"/>`;
|
|
924
|
-
contentTypes += `<Override PartName="/xl/worksheets/binaryIndex${sheet.sheetId}.bin" ContentType="application/vnd.ms-excel.binIndexWs"/>`;
|
|
925
|
-
}
|
|
926
|
-
contentTypes += `<Override PartName="/xl/styles.bin" ContentType="application/vnd.ms-excel.styles"/>
|
|
927
|
-
<Override PartName="/xl/sharedStrings.bin" ContentType="application/vnd.ms-excel.sharedStrings"/>
|
|
928
|
-
</Types>`;
|
|
929
|
-
this.archive.append(contentTypes, { name: '[Content_Types].xml' });
|
|
930
|
-
let wbRels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
931
|
-
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">`;
|
|
932
|
-
for (const sheet of this.sheetList) {
|
|
933
|
-
const rId = `rId${sheet.sheetId}`;
|
|
934
|
-
wbRels += `<Relationship Id="${rId}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/${sheet.nameInArchive}"/>`;
|
|
935
|
-
}
|
|
936
|
-
wbRels += `<Relationship Id="rId${this.sheetList.length + 2}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.bin"/>
|
|
937
|
-
<Relationship Id="rId${this.sheetList.length + 3}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.bin"/>
|
|
938
|
-
</Relationships>`;
|
|
939
|
-
this.archive.append(wbRels, { name: 'xl/_rels/workbook.bin.rels' });
|
|
940
|
-
const globalRels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
941
|
-
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
942
|
-
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.bin"/>
|
|
943
|
-
</Relationships>`;
|
|
944
|
-
this.archive.append(globalRels, { name: '_rels/.rels' });
|
|
945
|
-
for (const sheet of this.sheetList) {
|
|
946
|
-
const wsRels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
947
|
-
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
948
|
-
<Relationship Id="rId1" Type="http://schemas.microsoft.com/office/2006/relationships/xlBinaryIndex" Target="binaryIndex${sheet.sheetId}.bin"/>
|
|
949
|
-
</Relationships>`;
|
|
950
|
-
this.archive.append(wsRels, { name: `xl/worksheets/_rels/${sheet.nameInArchive}.rels` });
|
|
951
|
-
}
|
|
952
|
-
this.output.on('close', () => resolve());
|
|
953
|
-
this.archive.on('error', (err) => reject(err));
|
|
954
|
-
this.archive.finalize();
|
|
955
|
-
}
|
|
956
|
-
catch (err) {
|
|
957
|
-
reject(err);
|
|
958
|
-
}
|
|
959
|
-
});
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
exports.XlsbWriter = XlsbWriter;
|
|
963
|
-
exports.default = XlsbWriter;
|
|
964
|
-
//# sourceMappingURL=XlsbWriter.js.map
|