@simplysm/excel 13.0.75 → 13.0.76
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/package.json +2 -2
- package/tests/excel-cell.spec.ts +0 -71
- package/tests/excel-col.spec.ts +0 -31
- package/tests/excel-row.spec.ts +0 -10
- package/tests/excel-workbook.spec.ts +0 -14
- package/tests/excel-worksheet.spec.ts +0 -36
- package/tests/excel-wrapper.spec.ts +0 -23
- package/tests/utils/excel-utils.spec.ts +0 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/excel",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.76",
|
|
4
4
|
"description": "Excel file processing library",
|
|
5
5
|
"author": "simplysm",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"mime": "^4.1.0",
|
|
23
23
|
"zod": "^4.3.6",
|
|
24
|
-
"@simplysm/core-common": "13.0.
|
|
24
|
+
"@simplysm/core-common": "13.0.76"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/tests/excel-cell.spec.ts
CHANGED
|
@@ -92,30 +92,6 @@ describe("ExcelCell", () => {
|
|
|
92
92
|
expect(await ws.cell(0, 0).getVal()).toBeUndefined();
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
it("Can handle very large numbers", async () => {
|
|
96
|
-
const wb = new ExcelWorkbook();
|
|
97
|
-
const ws = await wb.createWorksheet("Test");
|
|
98
|
-
|
|
99
|
-
// Large number below MAX_SAFE_INTEGER
|
|
100
|
-
const bigNumber = Number.MAX_SAFE_INTEGER;
|
|
101
|
-
await ws.cell(0, 0).setVal(bigNumber);
|
|
102
|
-
|
|
103
|
-
const val = await ws.cell(0, 0).getVal();
|
|
104
|
-
expect(val).toBe(bigNumber);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("Can handle very small decimals", async () => {
|
|
108
|
-
const wb = new ExcelWorkbook();
|
|
109
|
-
const ws = await wb.createWorksheet("Test");
|
|
110
|
-
|
|
111
|
-
// Small decimal within Excel's precision range
|
|
112
|
-
const smallDecimal = 0.0001;
|
|
113
|
-
await ws.cell(0, 0).setVal(smallDecimal);
|
|
114
|
-
|
|
115
|
-
const val = await ws.cell(0, 0).getVal();
|
|
116
|
-
expect(val).toBeCloseTo(smallDecimal, 6);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
95
|
it("Throws error when setting unsupported type", async () => {
|
|
120
96
|
const wb = new ExcelWorkbook();
|
|
121
97
|
const ws = await wb.createWorksheet("Test");
|
|
@@ -321,53 +297,6 @@ describe("ExcelCell", () => {
|
|
|
321
297
|
});
|
|
322
298
|
|
|
323
299
|
describe("Cell Style", () => {
|
|
324
|
-
it("Can set background color", async () => {
|
|
325
|
-
const wb = new ExcelWorkbook();
|
|
326
|
-
const ws = await wb.createWorksheet("Test");
|
|
327
|
-
|
|
328
|
-
await ws.cell(0, 0).setVal("Colored");
|
|
329
|
-
await ws.cell(0, 0).setStyle({ background: "00FF0000" }); // Red
|
|
330
|
-
|
|
331
|
-
const styleId = await ws.cell(0, 0).getStyleId();
|
|
332
|
-
expect(styleId).toBeDefined();
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it("Can set borders", async () => {
|
|
336
|
-
const wb = new ExcelWorkbook();
|
|
337
|
-
const ws = await wb.createWorksheet("Test");
|
|
338
|
-
|
|
339
|
-
await ws.cell(0, 0).setVal("Bordered");
|
|
340
|
-
await ws.cell(0, 0).setStyle({ border: ["left", "right", "top", "bottom"] });
|
|
341
|
-
|
|
342
|
-
const styleId = await ws.cell(0, 0).getStyleId();
|
|
343
|
-
expect(styleId).toBeDefined();
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
it("Can set alignment", async () => {
|
|
347
|
-
const wb = new ExcelWorkbook();
|
|
348
|
-
const ws = await wb.createWorksheet("Test");
|
|
349
|
-
|
|
350
|
-
await ws.cell(0, 0).setVal("Aligned");
|
|
351
|
-
await ws.cell(0, 0).setStyle({
|
|
352
|
-
horizontalAlign: "center",
|
|
353
|
-
verticalAlign: "center",
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
const styleId = await ws.cell(0, 0).getStyleId();
|
|
357
|
-
expect(styleId).toBeDefined();
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
it("Can set number format", async () => {
|
|
361
|
-
const wb = new ExcelWorkbook();
|
|
362
|
-
const ws = await wb.createWorksheet("Test");
|
|
363
|
-
|
|
364
|
-
await ws.cell(0, 0).setVal(12345.6789);
|
|
365
|
-
await ws.cell(0, 0).setStyle({ numberFormat: "number" });
|
|
366
|
-
|
|
367
|
-
const styleId = await ws.cell(0, 0).getStyleId();
|
|
368
|
-
expect(styleId).toBeDefined();
|
|
369
|
-
});
|
|
370
|
-
|
|
371
300
|
it("Can set multiple styles simultaneously", async () => {
|
|
372
301
|
const wb = new ExcelWorkbook();
|
|
373
302
|
const ws = await wb.createWorksheet("Test");
|
package/tests/excel-col.spec.ts
CHANGED
|
@@ -25,16 +25,6 @@ describe("ExcelCol", () => {
|
|
|
25
25
|
expect(cell1).toBe(cell2);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
it("Returns different instance for different index", async () => {
|
|
29
|
-
const wb = new ExcelWorkbook();
|
|
30
|
-
const ws = await wb.createWorksheet("Test");
|
|
31
|
-
|
|
32
|
-
const col = ws.col(0);
|
|
33
|
-
const cell1 = col.cell(0);
|
|
34
|
-
const cell2 = col.cell(1);
|
|
35
|
-
|
|
36
|
-
expect(cell1).not.toBe(cell2);
|
|
37
|
-
});
|
|
38
28
|
});
|
|
39
29
|
|
|
40
30
|
describe("getCells()", () => {
|
|
@@ -87,26 +77,5 @@ describe("ExcelCol", () => {
|
|
|
87
77
|
expect(await ws2.cell(0, 0).getVal()).toBe("Test");
|
|
88
78
|
});
|
|
89
79
|
|
|
90
|
-
it("Can set different widths for multiple columns", async () => {
|
|
91
|
-
const wb = new ExcelWorkbook();
|
|
92
|
-
const ws = await wb.createWorksheet("Test");
|
|
93
|
-
|
|
94
|
-
await ws.cell(0, 0).setVal("A");
|
|
95
|
-
await ws.cell(0, 1).setVal("B");
|
|
96
|
-
await ws.cell(0, 2).setVal("C");
|
|
97
|
-
|
|
98
|
-
await ws.col(0).setWidth(10);
|
|
99
|
-
await ws.col(1).setWidth(20);
|
|
100
|
-
await ws.col(2).setWidth(30);
|
|
101
|
-
|
|
102
|
-
// Can round-trip without error
|
|
103
|
-
const bytes = await wb.getBytes();
|
|
104
|
-
const wb2 = new ExcelWorkbook(bytes);
|
|
105
|
-
const ws2 = await wb2.getWorksheet(0);
|
|
106
|
-
|
|
107
|
-
expect(await ws2.cell(0, 0).getVal()).toBe("A");
|
|
108
|
-
expect(await ws2.cell(0, 1).getVal()).toBe("B");
|
|
109
|
-
expect(await ws2.cell(0, 2).getVal()).toBe("C");
|
|
110
|
-
});
|
|
111
80
|
});
|
|
112
81
|
});
|
package/tests/excel-row.spec.ts
CHANGED
|
@@ -25,16 +25,6 @@ describe("ExcelRow", () => {
|
|
|
25
25
|
expect(cell1).toBe(cell2);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
it("returns different instances for different indices", async () => {
|
|
29
|
-
const wb = new ExcelWorkbook();
|
|
30
|
-
const ws = await wb.createWorksheet("Test");
|
|
31
|
-
|
|
32
|
-
const row = ws.row(0);
|
|
33
|
-
const cell1 = row.cell(0);
|
|
34
|
-
const cell2 = row.cell(1);
|
|
35
|
-
|
|
36
|
-
expect(cell1).not.toBe(cell2);
|
|
37
|
-
});
|
|
38
28
|
});
|
|
39
29
|
|
|
40
30
|
describe("getCells()", () => {
|
|
@@ -135,13 +135,6 @@ describe("ExcelWorkbook", () => {
|
|
|
135
135
|
await expect(wb.getWorksheetNames()).rejects.toThrow();
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
-
it("Error when calling createWorksheet() after close()", async () => {
|
|
139
|
-
const wb = new ExcelWorkbook();
|
|
140
|
-
await wb.close();
|
|
141
|
-
|
|
142
|
-
await expect(wb.createWorksheet("New")).rejects.toThrow();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
138
|
it("Error when calling getWorksheet() after close()", async () => {
|
|
146
139
|
const wb = new ExcelWorkbook();
|
|
147
140
|
await wb.createWorksheet("Test");
|
|
@@ -149,13 +142,6 @@ describe("ExcelWorkbook", () => {
|
|
|
149
142
|
|
|
150
143
|
await expect(wb.getWorksheet(0)).rejects.toThrow();
|
|
151
144
|
});
|
|
152
|
-
|
|
153
|
-
it("Error when calling getBytes() after close()", async () => {
|
|
154
|
-
const wb = new ExcelWorkbook();
|
|
155
|
-
await wb.close();
|
|
156
|
-
|
|
157
|
-
await expect(wb.getBytes()).rejects.toThrow();
|
|
158
|
-
});
|
|
159
145
|
});
|
|
160
146
|
|
|
161
147
|
describe("Reading real xlsx file", () => {
|
|
@@ -3,14 +3,6 @@ import { ExcelWorkbook } from "../src/excel-workbook";
|
|
|
3
3
|
|
|
4
4
|
describe("ExcelWorksheet", () => {
|
|
5
5
|
describe("Sheet name", () => {
|
|
6
|
-
it("should get sheet name", async () => {
|
|
7
|
-
const wb = new ExcelWorkbook();
|
|
8
|
-
const ws = await wb.createWorksheet("MySheet");
|
|
9
|
-
|
|
10
|
-
const name = await ws.getName();
|
|
11
|
-
expect(name).toBe("MySheet");
|
|
12
|
-
});
|
|
13
|
-
|
|
14
6
|
it("should change sheet name", async () => {
|
|
15
7
|
const wb = new ExcelWorkbook();
|
|
16
8
|
const ws = await wb.createWorksheet("OldName");
|
|
@@ -254,35 +246,7 @@ describe("ExcelWorksheet", () => {
|
|
|
254
246
|
});
|
|
255
247
|
});
|
|
256
248
|
|
|
257
|
-
describe("View settings", () => {
|
|
258
|
-
it("should set zoom level", async () => {
|
|
259
|
-
const wb = new ExcelWorkbook();
|
|
260
|
-
const ws = await wb.createWorksheet("Test");
|
|
261
|
-
|
|
262
|
-
await ws.setZoom(85);
|
|
263
|
-
// Success if set without error
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it("should set pane freeze", async () => {
|
|
267
|
-
const wb = new ExcelWorkbook();
|
|
268
|
-
const ws = await wb.createWorksheet("Test");
|
|
269
|
-
|
|
270
|
-
await ws.setFix({ r: 1 }); // Freeze 1 row
|
|
271
|
-
await ws.setFix({ c: 2 }); // Freeze 2 columns
|
|
272
|
-
await ws.setFix({ r: 1, c: 1 }); // Freeze 1 row and 1 column
|
|
273
|
-
// Success if set without error
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
|
|
277
249
|
describe("Column width", () => {
|
|
278
|
-
it("should set column width", async () => {
|
|
279
|
-
const wb = new ExcelWorkbook();
|
|
280
|
-
const ws = await wb.createWorksheet("Test");
|
|
281
|
-
|
|
282
|
-
await ws.col(0).setWidth(20);
|
|
283
|
-
// Success if set without error
|
|
284
|
-
});
|
|
285
|
-
|
|
286
250
|
it("should preserve column width after roundtrip", async () => {
|
|
287
251
|
const wb = new ExcelWorkbook();
|
|
288
252
|
const ws = await wb.createWorksheet("Test");
|
|
@@ -95,19 +95,6 @@ describe("ExcelWrapper", () => {
|
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
describe("Type conversion", () => {
|
|
98
|
-
it("can convert strings to numbers", async () => {
|
|
99
|
-
const wrapper = new ExcelWrapper(testSchema);
|
|
100
|
-
|
|
101
|
-
// Simulate Excel with values stored as strings manually
|
|
102
|
-
const wb = await wrapper.write("Test", [{ name: "Test", age: 25 }]);
|
|
103
|
-
const buffer = await wb.getBytes();
|
|
104
|
-
await wb.close();
|
|
105
|
-
|
|
106
|
-
const records = await wrapper.read(buffer);
|
|
107
|
-
expect(typeof records[0].age).toBe("number");
|
|
108
|
-
expect(records[0].age).toBe(25);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
98
|
it("applies default values", async () => {
|
|
112
99
|
const wrapper = new ExcelWrapper(testSchema);
|
|
113
100
|
|
|
@@ -216,16 +203,6 @@ describe("ExcelWrapper", () => {
|
|
|
216
203
|
await expect(wrapper.read(buffer, "NotExist")).rejects.toThrow();
|
|
217
204
|
});
|
|
218
205
|
|
|
219
|
-
it("throws error when reading with non-existent worksheet index", async () => {
|
|
220
|
-
const wrapper = new ExcelWrapper(testSchema);
|
|
221
|
-
|
|
222
|
-
const wb = await wrapper.write("Test", [{ name: "Test", age: 20 }]);
|
|
223
|
-
const buffer = await wb.getBytes();
|
|
224
|
-
await wb.close();
|
|
225
|
-
|
|
226
|
-
await expect(wrapper.read(buffer, 99)).rejects.toThrow();
|
|
227
|
-
});
|
|
228
|
-
|
|
229
206
|
it("throws error with worksheet name and detailed error when schema validation fails", async () => {
|
|
230
207
|
const strictSchema = z.object({
|
|
231
208
|
name: z.string().min(5).describe("이름"), // At least 5 characters
|
|
@@ -3,12 +3,6 @@ import { ExcelUtils } from "../../src/utils/excel-utils";
|
|
|
3
3
|
|
|
4
4
|
describe("ExcelUtils", () => {
|
|
5
5
|
describe("stringifyColAddr / parseColAddrCode", () => {
|
|
6
|
-
it("converts 0-25 to A-Z", () => {
|
|
7
|
-
expect(ExcelUtils.stringifyColAddr(0)).toBe("A");
|
|
8
|
-
expect(ExcelUtils.stringifyColAddr(1)).toBe("B");
|
|
9
|
-
expect(ExcelUtils.stringifyColAddr(25)).toBe("Z");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
6
|
it("converts 26 and above to AA, AB, etc.", () => {
|
|
13
7
|
expect(ExcelUtils.stringifyColAddr(26)).toBe("AA");
|
|
14
8
|
expect(ExcelUtils.stringifyColAddr(27)).toBe("AB");
|
|
@@ -27,25 +21,6 @@ describe("ExcelUtils", () => {
|
|
|
27
21
|
expect(ExcelUtils.parseColAddrCode("XFD")).toBe(16383);
|
|
28
22
|
});
|
|
29
23
|
|
|
30
|
-
it("parses A-Z to 0-25", () => {
|
|
31
|
-
expect(ExcelUtils.parseColAddrCode("A")).toBe(0);
|
|
32
|
-
expect(ExcelUtils.parseColAddrCode("B")).toBe(1);
|
|
33
|
-
expect(ExcelUtils.parseColAddrCode("Z")).toBe(25);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("parses AA, AB, etc. to 26 and above", () => {
|
|
37
|
-
expect(ExcelUtils.parseColAddrCode("AA")).toBe(26);
|
|
38
|
-
expect(ExcelUtils.parseColAddrCode("AB")).toBe(27);
|
|
39
|
-
expect(ExcelUtils.parseColAddrCode("AZ")).toBe(51);
|
|
40
|
-
expect(ExcelUtils.parseColAddrCode("BA")).toBe(52);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("parses column index from cell address", () => {
|
|
44
|
-
expect(ExcelUtils.parseColAddrCode("A1")).toBe(0);
|
|
45
|
-
expect(ExcelUtils.parseColAddrCode("B10")).toBe(1);
|
|
46
|
-
expect(ExcelUtils.parseColAddrCode("AA100")).toBe(26);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
24
|
it("round-trip: stringify → parse returns original value", () => {
|
|
50
25
|
for (let i = 0; i < 100; i++) {
|
|
51
26
|
const stringified = ExcelUtils.stringifyColAddr(i);
|
|
@@ -127,25 +102,6 @@ describe("ExcelUtils", () => {
|
|
|
127
102
|
expect(excelNum).toBeCloseTo(25569, 0);
|
|
128
103
|
});
|
|
129
104
|
|
|
130
|
-
it("correctly converts 2024-06-15", () => {
|
|
131
|
-
const date = new Date(Date.UTC(2024, 5, 15, 0, 0, 0));
|
|
132
|
-
const tick = date.getTime();
|
|
133
|
-
const excelNum = ExcelUtils.convertTimeTickToNumber(tick);
|
|
134
|
-
// Verify approximate value
|
|
135
|
-
expect(excelNum).toBeGreaterThan(45000);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("correctly converts date with time", () => {
|
|
139
|
-
const date = new Date(Date.UTC(2024, 5, 15, 12, 0, 0));
|
|
140
|
-
const tick = date.getTime();
|
|
141
|
-
const excelNum = ExcelUtils.convertTimeTickToNumber(tick);
|
|
142
|
-
// 12:00 = 0.5 days additional
|
|
143
|
-
const baseNum = ExcelUtils.convertTimeTickToNumber(
|
|
144
|
-
new Date(Date.UTC(2024, 5, 15, 0, 0, 0)).getTime(),
|
|
145
|
-
);
|
|
146
|
-
expect(excelNum - baseNum).toBeCloseTo(0.5, 1);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
105
|
it("round-trip: tick → number → tick returns original value", () => {
|
|
150
106
|
const originalDate = new Date(Date.UTC(2024, 5, 15, 14, 30, 45));
|
|
151
107
|
const tick = originalDate.getTime();
|