@simplysm/excel 13.0.76 → 13.0.78

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 (54) hide show
  1. package/README.md +539 -17
  2. package/dist/excel-cell.d.ts +4 -4
  3. package/dist/excel-cell.d.ts.map +1 -1
  4. package/dist/excel-cell.js +9 -10
  5. package/dist/excel-cell.js.map +1 -1
  6. package/dist/excel-workbook.d.ts +3 -3
  7. package/dist/excel-workbook.d.ts.map +1 -1
  8. package/dist/excel-workbook.js +3 -3
  9. package/dist/excel-workbook.js.map +1 -1
  10. package/dist/excel-worksheet.d.ts +1 -1
  11. package/dist/excel-worksheet.d.ts.map +1 -1
  12. package/dist/excel-worksheet.js +13 -17
  13. package/dist/excel-worksheet.js.map +1 -1
  14. package/dist/excel-wrapper.d.ts +1 -1
  15. package/dist/excel-wrapper.js +7 -7
  16. package/dist/excel-wrapper.js.map +1 -1
  17. package/dist/types.d.ts +1 -1
  18. package/dist/types.d.ts.map +1 -1
  19. package/dist/utils/excel-utils.d.ts +5 -5
  20. package/dist/utils/excel-utils.d.ts.map +1 -1
  21. package/dist/utils/excel-utils.js +15 -15
  22. package/dist/utils/excel-utils.js.map +1 -1
  23. package/dist/utils/zip-cache.js +3 -3
  24. package/dist/utils/zip-cache.js.map +1 -1
  25. package/dist/xml/excel-xml-relationship.js +2 -2
  26. package/dist/xml/excel-xml-relationship.js.map +1 -1
  27. package/dist/xml/excel-xml-style.js +16 -16
  28. package/dist/xml/excel-xml-style.js.map +1 -1
  29. package/dist/xml/excel-xml-workbook.js +6 -6
  30. package/dist/xml/excel-xml-workbook.js.map +1 -1
  31. package/dist/xml/excel-xml-worksheet.d.ts +5 -2
  32. package/dist/xml/excel-xml-worksheet.d.ts.map +1 -1
  33. package/dist/xml/excel-xml-worksheet.js +38 -20
  34. package/dist/xml/excel-xml-worksheet.js.map +1 -1
  35. package/package.json +2 -2
  36. package/src/excel-cell.ts +10 -11
  37. package/src/excel-workbook.ts +3 -3
  38. package/src/excel-worksheet.ts +17 -18
  39. package/src/excel-wrapper.ts +7 -7
  40. package/src/types.ts +1 -1
  41. package/src/utils/excel-utils.ts +15 -15
  42. package/src/utils/zip-cache.ts +3 -3
  43. package/src/xml/excel-xml-relationship.ts +2 -2
  44. package/src/xml/excel-xml-style.ts +16 -16
  45. package/src/xml/excel-xml-workbook.ts +6 -6
  46. package/src/xml/excel-xml-worksheet.ts +47 -22
  47. package/tests/excel-cell.spec.ts +85 -69
  48. package/tests/excel-col.spec.ts +17 -17
  49. package/tests/excel-row.spec.ts +13 -13
  50. package/tests/excel-workbook.spec.ts +26 -26
  51. package/tests/excel-worksheet.spec.ts +217 -101
  52. package/tests/excel-wrapper.spec.ts +24 -24
  53. package/tests/image-insert.spec.ts +5 -5
  54. package/tests/utils/excel-utils.spec.ts +14 -14
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
2
2
  import { ExcelWorkbook } from "../src/excel-workbook";
3
3
  import { ExcelXmlWorksheet } from "../src/xml/excel-xml-worksheet";
4
4
  import { DateOnly, DateTime, Time } from "@simplysm/core-common";
5
+ import type { ExcelCellData, ExcelCellType } from "../src";
5
6
 
6
7
  describe("ExcelXmlWorksheet.getCellVal - inline string", () => {
7
8
  it("should read plain string inline text (no attributes)", () => {
@@ -47,70 +48,70 @@ describe("ExcelCell", () => {
47
48
  describe("Cell Value Read/Write - Basic Types", () => {
48
49
  it("Can read and write string values", async () => {
49
50
  const wb = new ExcelWorkbook();
50
- const ws = await wb.createWorksheet("Test");
51
+ const ws = await wb.addWorksheet("Test");
51
52
 
52
- await ws.cell(0, 0).setVal("Hello World");
53
- const val = await ws.cell(0, 0).getVal();
53
+ await ws.cell(0, 0).setValue("Hello World");
54
+ const val = await ws.cell(0, 0).getValue();
54
55
 
55
56
  expect(val).toBe("Hello World");
56
57
  });
57
58
 
58
59
  it("Can read and write number values", async () => {
59
60
  const wb = new ExcelWorkbook();
60
- const ws = await wb.createWorksheet("Test");
61
+ const ws = await wb.addWorksheet("Test");
61
62
 
62
- await ws.cell(0, 0).setVal(12345);
63
- await ws.cell(0, 1).setVal(3.14159);
64
- await ws.cell(0, 2).setVal(-100);
65
- await ws.cell(0, 3).setVal(0);
63
+ await ws.cell(0, 0).setValue(12345);
64
+ await ws.cell(0, 1).setValue(3.14159);
65
+ await ws.cell(0, 2).setValue(-100);
66
+ await ws.cell(0, 3).setValue(0);
66
67
 
67
- expect(await ws.cell(0, 0).getVal()).toBe(12345);
68
- expect(await ws.cell(0, 1).getVal()).toBe(3.14159);
69
- expect(await ws.cell(0, 2).getVal()).toBe(-100);
70
- expect(await ws.cell(0, 3).getVal()).toBe(0);
68
+ expect(await ws.cell(0, 0).getValue()).toBe(12345);
69
+ expect(await ws.cell(0, 1).getValue()).toBe(3.14159);
70
+ expect(await ws.cell(0, 2).getValue()).toBe(-100);
71
+ expect(await ws.cell(0, 3).getValue()).toBe(0);
71
72
  });
72
73
 
73
74
  it("Can read and write boolean values", async () => {
74
75
  const wb = new ExcelWorkbook();
75
- const ws = await wb.createWorksheet("Test");
76
+ const ws = await wb.addWorksheet("Test");
76
77
 
77
- await ws.cell(0, 0).setVal(true);
78
- await ws.cell(0, 1).setVal(false);
78
+ await ws.cell(0, 0).setValue(true);
79
+ await ws.cell(0, 1).setValue(false);
79
80
 
80
- expect(await ws.cell(0, 0).getVal()).toBe(true);
81
- expect(await ws.cell(0, 1).getVal()).toBe(false);
81
+ expect(await ws.cell(0, 0).getValue()).toBe(true);
82
+ expect(await ws.cell(0, 1).getValue()).toBe(false);
82
83
  });
83
84
 
84
85
  it("Setting undefined value deletes the cell", async () => {
85
86
  const wb = new ExcelWorkbook();
86
- const ws = await wb.createWorksheet("Test");
87
+ const ws = await wb.addWorksheet("Test");
87
88
 
88
- await ws.cell(0, 0).setVal("Initial");
89
- expect(await ws.cell(0, 0).getVal()).toBe("Initial");
89
+ await ws.cell(0, 0).setValue("Initial");
90
+ expect(await ws.cell(0, 0).getValue()).toBe("Initial");
90
91
 
91
- await ws.cell(0, 0).setVal(undefined);
92
- expect(await ws.cell(0, 0).getVal()).toBeUndefined();
92
+ await ws.cell(0, 0).setValue(undefined);
93
+ expect(await ws.cell(0, 0).getValue()).toBeUndefined();
93
94
  });
94
95
 
95
96
  it("Throws error when setting unsupported type", async () => {
96
97
  const wb = new ExcelWorkbook();
97
- const ws = await wb.createWorksheet("Test");
98
+ const ws = await wb.addWorksheet("Test");
98
99
 
99
- await expect(ws.cell(0, 0).setVal({} as any)).rejects.toThrow("Unsupported type");
100
+ await expect(ws.cell(0, 0).setValue({} as any)).rejects.toThrow("Unsupported type");
100
101
 
101
- await expect(ws.cell(0, 1).setVal([] as any)).rejects.toThrow("Unsupported type");
102
+ await expect(ws.cell(0, 1).setValue([] as any)).rejects.toThrow("Unsupported type");
102
103
  });
103
104
  });
104
105
 
105
106
  describe("Cell Value Read/Write - Date/Time Types", () => {
106
107
  it("Can read and write DateOnly values", async () => {
107
108
  const wb = new ExcelWorkbook();
108
- const ws = await wb.createWorksheet("Test");
109
+ const ws = await wb.addWorksheet("Test");
109
110
 
110
111
  const date = new DateOnly(2024, 6, 15);
111
- await ws.cell(0, 0).setVal(date);
112
+ await ws.cell(0, 0).setValue(date);
112
113
 
113
- const val = await ws.cell(0, 0).getVal();
114
+ const val = await ws.cell(0, 0).getValue();
114
115
  expect(val).toBeInstanceOf(DateOnly);
115
116
  expect((val as DateOnly).year).toBe(2024);
116
117
  expect((val as DateOnly).month).toBe(6);
@@ -119,12 +120,12 @@ describe("ExcelCell", () => {
119
120
 
120
121
  it("Can read and write DateTime values", async () => {
121
122
  const wb = new ExcelWorkbook();
122
- const ws = await wb.createWorksheet("Test");
123
+ const ws = await wb.addWorksheet("Test");
123
124
 
124
125
  const dateTime = new DateTime(2024, 6, 15, 14, 30, 45);
125
- await ws.cell(0, 0).setVal(dateTime);
126
+ await ws.cell(0, 0).setValue(dateTime);
126
127
 
127
- const val = await ws.cell(0, 0).getVal();
128
+ const val = await ws.cell(0, 0).getValue();
128
129
  expect(val).toBeInstanceOf(DateTime);
129
130
  expect((val as DateTime).year).toBe(2024);
130
131
  expect((val as DateTime).month).toBe(6);
@@ -136,12 +137,12 @@ describe("ExcelCell", () => {
136
137
 
137
138
  it("Can read and write Time values", async () => {
138
139
  const wb = new ExcelWorkbook();
139
- const ws = await wb.createWorksheet("Test");
140
+ const ws = await wb.addWorksheet("Test");
140
141
 
141
142
  const time = new Time(14, 30, 45);
142
- await ws.cell(0, 0).setVal(time);
143
+ await ws.cell(0, 0).setValue(time);
143
144
 
144
- const val = await ws.cell(0, 0).getVal();
145
+ const val = await ws.cell(0, 0).getValue();
145
146
  expect(val).toBeInstanceOf(Time);
146
147
  expect((val as Time).hour).toBe(14);
147
148
  expect((val as Time).minute).toBe(30);
@@ -150,18 +151,18 @@ describe("ExcelCell", () => {
150
151
 
151
152
  it("DateOnly values persist after round-trip", async () => {
152
153
  const wb = new ExcelWorkbook();
153
- const ws = await wb.createWorksheet("Test");
154
+ const ws = await wb.addWorksheet("Test");
154
155
 
155
156
  const date = new DateOnly(2024, 6, 15);
156
- await ws.cell(0, 0).setVal(date);
157
+ await ws.cell(0, 0).setValue(date);
157
158
 
158
- const bytes = await wb.getBytes();
159
+ const bytes = await wb.toBytes();
159
160
  await wb.close();
160
161
 
161
162
  const wb2 = new ExcelWorkbook(bytes);
162
163
  const ws2 = await wb2.getWorksheet(0);
163
164
 
164
- const val = await ws2.cell(0, 0).getVal();
165
+ const val = await ws2.cell(0, 0).getValue();
165
166
  expect(val).toBeInstanceOf(DateOnly);
166
167
  expect((val as DateOnly).year).toBe(2024);
167
168
  expect((val as DateOnly).month).toBe(6);
@@ -171,18 +172,18 @@ describe("ExcelCell", () => {
171
172
 
172
173
  it("DateTime values persist after round-trip", async () => {
173
174
  const wb = new ExcelWorkbook();
174
- const ws = await wb.createWorksheet("Test");
175
+ const ws = await wb.addWorksheet("Test");
175
176
 
176
177
  const dateTime = new DateTime(2024, 6, 15, 14, 30, 45);
177
- await ws.cell(0, 0).setVal(dateTime);
178
+ await ws.cell(0, 0).setValue(dateTime);
178
179
 
179
- const bytes = await wb.getBytes();
180
+ const bytes = await wb.toBytes();
180
181
  await wb.close();
181
182
 
182
183
  const wb2 = new ExcelWorkbook(bytes);
183
184
  const ws2 = await wb2.getWorksheet(0);
184
185
 
185
- const val = await ws2.cell(0, 0).getVal();
186
+ const val = await ws2.cell(0, 0).getValue();
186
187
  expect(val).toBeInstanceOf(DateTime);
187
188
  expect((val as DateTime).year).toBe(2024);
188
189
  expect((val as DateTime).month).toBe(6);
@@ -195,18 +196,18 @@ describe("ExcelCell", () => {
195
196
 
196
197
  it("Time values persist after round-trip", async () => {
197
198
  const wb = new ExcelWorkbook();
198
- const ws = await wb.createWorksheet("Test");
199
+ const ws = await wb.addWorksheet("Test");
199
200
 
200
201
  const time = new Time(14, 30, 45);
201
- await ws.cell(0, 0).setVal(time);
202
+ await ws.cell(0, 0).setValue(time);
202
203
 
203
- const bytes = await wb.getBytes();
204
+ const bytes = await wb.toBytes();
204
205
  await wb.close();
205
206
 
206
207
  const wb2 = new ExcelWorkbook(bytes);
207
208
  const ws2 = await wb2.getWorksheet(0);
208
209
 
209
- const val = await ws2.cell(0, 0).getVal();
210
+ const val = await ws2.cell(0, 0).getValue();
210
211
  expect(val).toBeInstanceOf(Time);
211
212
  expect((val as Time).hour).toBe(14);
212
213
  expect((val as Time).minute).toBe(30);
@@ -218,10 +219,10 @@ describe("ExcelCell", () => {
218
219
  describe("Formulas", () => {
219
220
  it("Can set formulas", async () => {
220
221
  const wb = new ExcelWorkbook();
221
- const ws = await wb.createWorksheet("Test");
222
+ const ws = await wb.addWorksheet("Test");
222
223
 
223
- await ws.cell(0, 0).setVal(10);
224
- await ws.cell(0, 1).setVal(20);
224
+ await ws.cell(0, 0).setValue(10);
225
+ await ws.cell(0, 1).setValue(20);
225
226
  await ws.cell(0, 2).setFormula("A1+B1");
226
227
 
227
228
  // Verify formula directly
@@ -229,7 +230,7 @@ describe("ExcelCell", () => {
229
230
  expect(formula).toBe("A1+B1");
230
231
 
231
232
  // Also verify with round-trip
232
- const buffer = await wb.getBytes();
233
+ const buffer = await wb.toBytes();
233
234
 
234
235
  const wb2 = new ExcelWorkbook(buffer);
235
236
  const ws2 = await wb2.getWorksheet(0);
@@ -239,13 +240,13 @@ describe("ExcelCell", () => {
239
240
 
240
241
  it("Formulas persist after round-trip", async () => {
241
242
  const wb = new ExcelWorkbook();
242
- const ws = await wb.createWorksheet("Test");
243
+ const ws = await wb.addWorksheet("Test");
243
244
 
244
- await ws.cell(0, 0).setVal(10);
245
- await ws.cell(0, 1).setVal(20);
245
+ await ws.cell(0, 0).setValue(10);
246
+ await ws.cell(0, 1).setValue(20);
246
247
  await ws.cell(0, 2).setFormula("SUM(A1:B1)");
247
248
 
248
- const buffer = await wb.getBytes();
249
+ const buffer = await wb.toBytes();
249
250
  await wb.close();
250
251
 
251
252
  const wb2 = new ExcelWorkbook(buffer);
@@ -259,35 +260,35 @@ describe("ExcelCell", () => {
259
260
 
260
261
  it("Setting formula to undefined deletes it", async () => {
261
262
  const wb = new ExcelWorkbook();
262
- const ws = await wb.createWorksheet("Test");
263
+ const ws = await wb.addWorksheet("Test");
263
264
 
264
265
  await ws.cell(0, 0).setFormula("A1+B1");
265
266
  await ws.cell(0, 0).setFormula(undefined);
266
267
 
267
- expect(await ws.cell(0, 0).getVal()).toBeUndefined();
268
+ expect(await ws.cell(0, 0).getValue()).toBeUndefined();
268
269
  });
269
270
  });
270
271
 
271
272
  describe("Cell Merge", () => {
272
273
  it("Can merge cells", async () => {
273
274
  const wb = new ExcelWorkbook();
274
- const ws = await wb.createWorksheet("Test");
275
+ const ws = await wb.addWorksheet("Test");
275
276
 
276
- await ws.cell(0, 0).setVal("Merged");
277
+ await ws.cell(0, 0).setValue("Merged");
277
278
  await ws.cell(0, 0).merge(2, 3); // Merge 2 rows x 3 columns
278
279
 
279
280
  // Verify merge with round-trip
280
- const buffer = await wb.getBytes();
281
+ const buffer = await wb.toBytes();
281
282
  const wb2 = new ExcelWorkbook(buffer);
282
283
  const ws2 = await wb2.getWorksheet(0);
283
284
 
284
- const val = await ws2.cell(0, 0).getVal();
285
+ const val = await ws2.cell(0, 0).getValue();
285
286
  expect(val).toBe("Merged");
286
287
  });
287
288
 
288
289
  it("Throws error when attempting to merge overlapping ranges", async () => {
289
290
  const wb = new ExcelWorkbook();
290
- const ws = await wb.createWorksheet("Test");
291
+ const ws = await wb.addWorksheet("Test");
291
292
 
292
293
  await ws.cell(0, 0).merge(2, 2); // Merge A1:B2
293
294
 
@@ -299,9 +300,9 @@ describe("ExcelCell", () => {
299
300
  describe("Cell Style", () => {
300
301
  it("Can set multiple styles simultaneously", async () => {
301
302
  const wb = new ExcelWorkbook();
302
- const ws = await wb.createWorksheet("Test");
303
+ const ws = await wb.addWorksheet("Test");
303
304
 
304
- await ws.cell(0, 0).setVal("Multi-Style");
305
+ await ws.cell(0, 0).setValue("Multi-Style");
305
306
  await ws.cell(0, 0).setStyle({
306
307
  background: "00FFFF00",
307
308
  border: ["left", "right"],
@@ -315,18 +316,18 @@ describe("ExcelCell", () => {
315
316
 
316
317
  it("Throws error for invalid color format", async () => {
317
318
  const wb = new ExcelWorkbook();
318
- const ws = await wb.createWorksheet("Test");
319
+ const ws = await wb.addWorksheet("Test");
319
320
 
320
- await ws.cell(0, 0).setVal("Test");
321
+ await ws.cell(0, 0).setValue("Test");
321
322
  await expect(ws.cell(0, 0).setStyle({ background: "invalid" })).rejects.toThrow();
322
323
  });
323
324
 
324
325
  it("Styles persist after round-trip", async () => {
325
326
  const wb = new ExcelWorkbook();
326
- const ws = await wb.createWorksheet("Test");
327
+ const ws = await wb.addWorksheet("Test");
327
328
 
328
329
  // Set various styles
329
- await ws.cell(0, 0).setVal("Styled");
330
+ await ws.cell(0, 0).setValue("Styled");
330
331
  await ws.cell(0, 0).setStyle({
331
332
  background: "00FF0000", // Red
332
333
  border: ["left", "right", "top", "bottom"],
@@ -334,14 +335,14 @@ describe("ExcelCell", () => {
334
335
  verticalAlign: "top",
335
336
  });
336
337
 
337
- const bytes = await wb.getBytes();
338
+ const bytes = await wb.toBytes();
338
339
 
339
340
  // Verify styles after round-trip
340
341
  const wb2 = new ExcelWorkbook(bytes);
341
342
  const ws2 = await wb2.getWorksheet("Test");
342
343
 
343
344
  // Verify value
344
- const val = await ws2.cell(0, 0).getVal();
345
+ const val = await ws2.cell(0, 0).getValue();
345
346
  expect(val).toBe("Styled");
346
347
 
347
348
  // Verify style ID exists
@@ -375,3 +376,18 @@ describe("ExcelCell", () => {
375
376
  });
376
377
  });
377
378
  });
379
+
380
+ describe("ExcelCellData type narrowing", () => {
381
+ it("should type cell type field as ExcelCellType", () => {
382
+ const cellData: ExcelCellData = {
383
+ $: { r: "A1", t: "s" },
384
+ v: ["test"],
385
+ };
386
+
387
+ const cellType: ExcelCellType | undefined = cellData.$.t;
388
+ expect(cellType).toBe("s");
389
+
390
+ // This should compile: no cast needed
391
+ expect(["s", "b", "str", "n", "inlineStr", "e", undefined].includes(cellData.$.t)).toBe(true);
392
+ });
393
+ });
@@ -5,18 +5,18 @@ describe("ExcelCol", () => {
5
5
  describe("cell()", () => {
6
6
  it("Returns cell corresponding to row index", async () => {
7
7
  const wb = new ExcelWorkbook();
8
- const ws = await wb.createWorksheet("Test");
8
+ const ws = await wb.addWorksheet("Test");
9
9
 
10
10
  const col = ws.col(0);
11
11
  const cell = col.cell(0);
12
12
 
13
- await cell.setVal("Hello");
14
- expect(await cell.getVal()).toBe("Hello");
13
+ await cell.setValue("Hello");
14
+ expect(await cell.getValue()).toBe("Hello");
15
15
  });
16
16
 
17
17
  it("Returns same instance for same index (caching)", async () => {
18
18
  const wb = new ExcelWorkbook();
19
- const ws = await wb.createWorksheet("Test");
19
+ const ws = await wb.addWorksheet("Test");
20
20
 
21
21
  const col = ws.col(0);
22
22
  const cell1 = col.cell(0);
@@ -30,51 +30,51 @@ describe("ExcelCol", () => {
30
30
  describe("getCells()", () => {
31
31
  it("Returns all cells within range", async () => {
32
32
  const wb = new ExcelWorkbook();
33
- const ws = await wb.createWorksheet("Test");
33
+ const ws = await wb.addWorksheet("Test");
34
34
 
35
35
  // Set data to define range
36
- await ws.cell(0, 0).setVal("A1");
37
- await ws.cell(1, 0).setVal("A2");
38
- await ws.cell(2, 0).setVal("A3");
36
+ await ws.cell(0, 0).setValue("A1");
37
+ await ws.cell(1, 0).setValue("A2");
38
+ await ws.cell(2, 0).setValue("A3");
39
39
 
40
40
  const col = ws.col(0);
41
41
  const cells = await col.getCells();
42
42
 
43
43
  expect(cells.length).toBeGreaterThanOrEqual(3);
44
- expect(await cells[0].getVal()).toBe("A1");
45
- expect(await cells[1].getVal()).toBe("A2");
46
- expect(await cells[2].getVal()).toBe("A3");
44
+ expect(await cells[0].getValue()).toBe("A1");
45
+ expect(await cells[1].getValue()).toBe("A2");
46
+ expect(await cells[2].getValue()).toBe("A3");
47
47
  });
48
48
 
49
49
  it("Returns cell corresponding to default range (0,0) from empty worksheet", async () => {
50
50
  const wb = new ExcelWorkbook();
51
- const ws = await wb.createWorksheet("Test");
51
+ const ws = await wb.addWorksheet("Test");
52
52
 
53
53
  const col = ws.col(0);
54
54
  const cells = await col.getCells();
55
55
 
56
56
  // Default range of empty worksheet is (0,0)-(0,0), so returns one cell
57
57
  expect(cells.length).toBe(1);
58
- expect(await cells[0].getVal()).toBeUndefined();
58
+ expect(await cells[0].getValue()).toBeUndefined();
59
59
  });
60
60
  });
61
61
 
62
62
  describe("setWidth()", () => {
63
63
  it("Can set column width", async () => {
64
64
  const wb = new ExcelWorkbook();
65
- const ws = await wb.createWorksheet("Test");
65
+ const ws = await wb.addWorksheet("Test");
66
66
 
67
67
  // Add data and set width
68
- await ws.cell(0, 0).setVal("Test");
68
+ await ws.cell(0, 0).setValue("Test");
69
69
  await ws.col(0).setWidth(20);
70
70
 
71
71
  // Verify settings via round-trip
72
- const bytes = await wb.getBytes();
72
+ const bytes = await wb.toBytes();
73
73
  const wb2 = new ExcelWorkbook(bytes);
74
74
  const ws2 = await wb2.getWorksheet(0);
75
75
 
76
76
  // Verify value is preserved (width is hard to verify directly, so just check it works without error)
77
- expect(await ws2.cell(0, 0).getVal()).toBe("Test");
77
+ expect(await ws2.cell(0, 0).getValue()).toBe("Test");
78
78
  });
79
79
 
80
80
  });
@@ -5,18 +5,18 @@ describe("ExcelRow", () => {
5
5
  describe("cell()", () => {
6
6
  it("returns cell corresponding to column index", async () => {
7
7
  const wb = new ExcelWorkbook();
8
- const ws = await wb.createWorksheet("Test");
8
+ const ws = await wb.addWorksheet("Test");
9
9
 
10
10
  const row = ws.row(0);
11
11
  const cell = row.cell(0);
12
12
 
13
- await cell.setVal("Hello");
14
- expect(await cell.getVal()).toBe("Hello");
13
+ await cell.setValue("Hello");
14
+ expect(await cell.getValue()).toBe("Hello");
15
15
  });
16
16
 
17
17
  it("returns same instance for same index (caching)", async () => {
18
18
  const wb = new ExcelWorkbook();
19
- const ws = await wb.createWorksheet("Test");
19
+ const ws = await wb.addWorksheet("Test");
20
20
 
21
21
  const row = ws.row(0);
22
22
  const cell1 = row.cell(0);
@@ -30,32 +30,32 @@ describe("ExcelRow", () => {
30
30
  describe("getCells()", () => {
31
31
  it("returns all cells within range", async () => {
32
32
  const wb = new ExcelWorkbook();
33
- const ws = await wb.createWorksheet("Test");
33
+ const ws = await wb.addWorksheet("Test");
34
34
 
35
35
  // Set range by configuring data
36
- await ws.cell(0, 0).setVal("A1");
37
- await ws.cell(0, 1).setVal("B1");
38
- await ws.cell(0, 2).setVal("C1");
36
+ await ws.cell(0, 0).setValue("A1");
37
+ await ws.cell(0, 1).setValue("B1");
38
+ await ws.cell(0, 2).setValue("C1");
39
39
 
40
40
  const row = ws.row(0);
41
41
  const cells = await row.getCells();
42
42
 
43
43
  expect(cells.length).toBeGreaterThanOrEqual(3);
44
- expect(await cells[0].getVal()).toBe("A1");
45
- expect(await cells[1].getVal()).toBe("B1");
46
- expect(await cells[2].getVal()).toBe("C1");
44
+ expect(await cells[0].getValue()).toBe("A1");
45
+ expect(await cells[1].getValue()).toBe("B1");
46
+ expect(await cells[2].getValue()).toBe("C1");
47
47
  });
48
48
 
49
49
  it("returns cell corresponding to default range (0,0) in empty worksheet", async () => {
50
50
  const wb = new ExcelWorkbook();
51
- const ws = await wb.createWorksheet("Test");
51
+ const ws = await wb.addWorksheet("Test");
52
52
 
53
53
  const row = ws.row(0);
54
54
  const cells = await row.getCells();
55
55
 
56
56
  // Empty worksheet default range is (0,0)-(0,0) so returns one cell
57
57
  expect(cells.length).toBe(1);
58
- expect(await cells[0].getVal()).toBeUndefined();
58
+ expect(await cells[0].getValue()).toBeUndefined();
59
59
  });
60
60
  });
61
61
  });
@@ -6,7 +6,7 @@ describe("ExcelWorkbook", () => {
6
6
  describe("Creating empty workbook", () => {
7
7
  it("Can create a worksheet", async () => {
8
8
  const wb = new ExcelWorkbook();
9
- const ws = await wb.createWorksheet("TestSheet");
9
+ const ws = await wb.addWorksheet("TestSheet");
10
10
 
11
11
  expect(ws).toBeDefined();
12
12
  const name = await ws.getName();
@@ -15,9 +15,9 @@ describe("ExcelWorkbook", () => {
15
15
 
16
16
  it("Can create multiple worksheets", async () => {
17
17
  const wb = new ExcelWorkbook();
18
- await wb.createWorksheet("Sheet1");
19
- await wb.createWorksheet("Sheet2");
20
- await wb.createWorksheet("Sheet3");
18
+ await wb.addWorksheet("Sheet1");
19
+ await wb.addWorksheet("Sheet2");
20
+ await wb.addWorksheet("Sheet3");
21
21
 
22
22
  const names = await wb.getWorksheetNames();
23
23
  expect(names).toEqual(["Sheet1", "Sheet2", "Sheet3"]);
@@ -27,8 +27,8 @@ describe("ExcelWorkbook", () => {
27
27
  describe("Accessing worksheets", () => {
28
28
  it("Can get worksheet by index", async () => {
29
29
  const wb = new ExcelWorkbook();
30
- await wb.createWorksheet("First");
31
- await wb.createWorksheet("Second");
30
+ await wb.addWorksheet("First");
31
+ await wb.addWorksheet("Second");
32
32
 
33
33
  const ws = await wb.getWorksheet(1);
34
34
  const name = await ws.getName();
@@ -37,7 +37,7 @@ describe("ExcelWorkbook", () => {
37
37
 
38
38
  it("Can get worksheet by name", async () => {
39
39
  const wb = new ExcelWorkbook();
40
- await wb.createWorksheet("MySheet");
40
+ await wb.addWorksheet("MySheet");
41
41
 
42
42
  const ws = await wb.getWorksheet("MySheet");
43
43
  const name = await ws.getName();
@@ -46,7 +46,7 @@ describe("ExcelWorkbook", () => {
46
46
 
47
47
  it("Error when accessing non-existent sheet", async () => {
48
48
  const wb = new ExcelWorkbook();
49
- await wb.createWorksheet("Sheet1");
49
+ await wb.addWorksheet("Sheet1");
50
50
 
51
51
  await expect(wb.getWorksheet("NotExist")).rejects.toThrow();
52
52
  await expect(wb.getWorksheet(10)).rejects.toThrow();
@@ -56,20 +56,20 @@ describe("ExcelWorkbook", () => {
56
56
  describe("Bytes/Blob export", () => {
57
57
  it("Can export as Bytes", async () => {
58
58
  const wb = new ExcelWorkbook();
59
- const ws = await wb.createWorksheet("Test");
60
- await ws.cell(0, 0).setVal("Hello");
59
+ const ws = await wb.addWorksheet("Test");
60
+ await ws.cell(0, 0).setValue("Hello");
61
61
 
62
- const bytes: Bytes = await wb.getBytes();
62
+ const bytes: Bytes = await wb.toBytes();
63
63
  expect(bytes).toBeInstanceOf(Uint8Array);
64
64
  expect(bytes.length).toBeGreaterThan(0);
65
65
  });
66
66
 
67
67
  it("Can export as Blob", async () => {
68
68
  const wb = new ExcelWorkbook();
69
- const ws = await wb.createWorksheet("Test");
70
- await ws.cell(0, 0).setVal("Hello");
69
+ const ws = await wb.addWorksheet("Test");
70
+ await ws.cell(0, 0).setValue("Hello");
71
71
 
72
- const blob = await wb.getBlob();
72
+ const blob = await wb.toBlob();
73
73
  expect(blob).toBeInstanceOf(Blob);
74
74
  expect(blob.type).toBe("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
75
75
  expect(blob.size).toBeGreaterThan(0);
@@ -80,9 +80,9 @@ describe("ExcelWorkbook", () => {
80
80
  it("Can create workbook from Blob", async () => {
81
81
  // First create workbook with Bytes
82
82
  const wb1 = new ExcelWorkbook();
83
- const ws1 = await wb1.createWorksheet("Test");
84
- await ws1.cell(0, 0).setVal("BlobTest");
85
- const bytes = await wb1.getBytes();
83
+ const ws1 = await wb1.addWorksheet("Test");
84
+ await ws1.cell(0, 0).setValue("BlobTest");
85
+ const bytes = await wb1.toBytes();
86
86
  await wb1.close();
87
87
 
88
88
  // Convert to Blob
@@ -93,7 +93,7 @@ describe("ExcelWorkbook", () => {
93
93
  // Read workbook from Blob
94
94
  const wb2 = new ExcelWorkbook(blob);
95
95
  const ws2 = await wb2.getWorksheet(0);
96
- const val = await ws2.cell(0, 0).getVal();
96
+ const val = await ws2.cell(0, 0).getValue();
97
97
 
98
98
  expect(val).toBe("BlobTest");
99
99
  await wb2.close();
@@ -102,12 +102,12 @@ describe("ExcelWorkbook", () => {
102
102
  it("Can save created workbook as Bytes and read again", async () => {
103
103
  // Create
104
104
  const wb1 = new ExcelWorkbook();
105
- const ws1 = await wb1.createWorksheet("RoundTrip");
106
- await ws1.cell(0, 0).setVal("TestValue");
107
- await ws1.cell(0, 1).setVal(12345);
105
+ const ws1 = await wb1.addWorksheet("RoundTrip");
106
+ await ws1.cell(0, 0).setValue("TestValue");
107
+ await ws1.cell(0, 1).setValue(12345);
108
108
 
109
109
  // Save
110
- const bytes = await wb1.getBytes();
110
+ const bytes = await wb1.toBytes();
111
111
  await wb1.close();
112
112
 
113
113
  // Read again
@@ -116,8 +116,8 @@ describe("ExcelWorkbook", () => {
116
116
  expect(names).toContain("RoundTrip");
117
117
 
118
118
  const ws2 = await wb2.getWorksheet("RoundTrip");
119
- const val1 = await ws2.cell(0, 0).getVal();
120
- const val2 = await ws2.cell(0, 1).getVal();
119
+ const val1 = await ws2.cell(0, 0).getValue();
120
+ const val2 = await ws2.cell(0, 1).getValue();
121
121
 
122
122
  expect(val1).toBe("TestValue");
123
123
  expect(val2).toBe(12345);
@@ -129,7 +129,7 @@ describe("ExcelWorkbook", () => {
129
129
  describe("Error after resource cleanup", () => {
130
130
  it("Error when calling getWorksheetNames() after close()", async () => {
131
131
  const wb = new ExcelWorkbook();
132
- await wb.createWorksheet("Test");
132
+ await wb.addWorksheet("Test");
133
133
  await wb.close();
134
134
 
135
135
  await expect(wb.getWorksheetNames()).rejects.toThrow();
@@ -137,7 +137,7 @@ describe("ExcelWorkbook", () => {
137
137
 
138
138
  it("Error when calling getWorksheet() after close()", async () => {
139
139
  const wb = new ExcelWorkbook();
140
- await wb.createWorksheet("Test");
140
+ await wb.addWorksheet("Test");
141
141
  await wb.close();
142
142
 
143
143
  await expect(wb.getWorksheet(0)).rejects.toThrow();