@simplysm/excel 13.0.100 → 14.0.4

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 (97) hide show
  1. package/README.md +66 -78
  2. package/dist/excel-cell.d.ts +28 -28
  3. package/dist/excel-cell.d.ts.map +1 -1
  4. package/dist/excel-cell.js +273 -264
  5. package/dist/excel-cell.js.map +1 -6
  6. package/dist/excel-col.d.ts +4 -4
  7. package/dist/excel-col.d.ts.map +1 -1
  8. package/dist/excel-col.js +33 -35
  9. package/dist/excel-col.js.map +1 -6
  10. package/dist/excel-row.d.ts +3 -3
  11. package/dist/excel-row.d.ts.map +1 -1
  12. package/dist/excel-row.js +28 -30
  13. package/dist/excel-row.js.map +1 -6
  14. package/dist/excel-workbook.d.ts +23 -23
  15. package/dist/excel-workbook.d.ts.map +1 -1
  16. package/dist/excel-workbook.js +151 -125
  17. package/dist/excel-workbook.js.map +1 -6
  18. package/dist/excel-worksheet.d.ts +32 -32
  19. package/dist/excel-worksheet.d.ts.map +1 -1
  20. package/dist/excel-worksheet.js +281 -253
  21. package/dist/excel-worksheet.js.map +1 -6
  22. package/dist/excel-wrapper.d.ts +7 -7
  23. package/dist/excel-wrapper.d.ts.map +1 -1
  24. package/dist/excel-wrapper.js +190 -226
  25. package/dist/excel-wrapper.js.map +1 -6
  26. package/dist/index.js +4 -1
  27. package/dist/index.js.map +1 -6
  28. package/dist/types.d.ts +13 -13
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/types.js +3 -1
  31. package/dist/types.js.map +1 -6
  32. package/dist/utils/excel-utils.d.ts +23 -23
  33. package/dist/utils/excel-utils.d.ts.map +1 -1
  34. package/dist/utils/excel-utils.js +183 -151
  35. package/dist/utils/excel-utils.js.map +1 -6
  36. package/dist/utils/zip-cache.d.ts +6 -6
  37. package/dist/utils/zip-cache.js +78 -60
  38. package/dist/utils/zip-cache.js.map +1 -6
  39. package/dist/xml/excel-xml-content-type.d.ts +2 -2
  40. package/dist/xml/excel-xml-content-type.js +55 -53
  41. package/dist/xml/excel-xml-content-type.js.map +1 -6
  42. package/dist/xml/excel-xml-drawing.d.ts +2 -2
  43. package/dist/xml/excel-xml-drawing.js +74 -73
  44. package/dist/xml/excel-xml-drawing.js.map +1 -6
  45. package/dist/xml/excel-xml-relationship.d.ts +2 -2
  46. package/dist/xml/excel-xml-relationship.js +67 -67
  47. package/dist/xml/excel-xml-relationship.js.map +1 -6
  48. package/dist/xml/excel-xml-shared-string.d.ts +2 -2
  49. package/dist/xml/excel-xml-shared-string.js +57 -55
  50. package/dist/xml/excel-xml-shared-string.js.map +1 -6
  51. package/dist/xml/excel-xml-style.d.ts +2 -2
  52. package/dist/xml/excel-xml-style.js +311 -295
  53. package/dist/xml/excel-xml-style.js.map +1 -6
  54. package/dist/xml/excel-xml-unknown.d.ts +2 -2
  55. package/dist/xml/excel-xml-unknown.js +11 -10
  56. package/dist/xml/excel-xml-unknown.js.map +1 -6
  57. package/dist/xml/excel-xml-workbook.d.ts +3 -2
  58. package/dist/xml/excel-xml-workbook.d.ts.map +1 -1
  59. package/dist/xml/excel-xml-workbook.js +95 -90
  60. package/dist/xml/excel-xml-workbook.js.map +1 -6
  61. package/dist/xml/excel-xml-worksheet.d.ts +6 -6
  62. package/dist/xml/excel-xml-worksheet.js +450 -393
  63. package/dist/xml/excel-xml-worksheet.js.map +1 -6
  64. package/docs/core.md +147 -0
  65. package/docs/types.md +201 -212
  66. package/docs/wrapper.md +32 -62
  67. package/package.json +8 -6
  68. package/src/excel-cell.ts +36 -36
  69. package/src/excel-col.ts +4 -4
  70. package/src/excel-row.ts +3 -3
  71. package/src/excel-workbook.ts +38 -38
  72. package/src/excel-worksheet.ts +69 -51
  73. package/src/excel-wrapper.ts +55 -50
  74. package/src/index.ts +3 -3
  75. package/src/types.ts +17 -17
  76. package/src/utils/excel-utils.ts +47 -41
  77. package/src/utils/zip-cache.ts +6 -6
  78. package/src/xml/excel-xml-content-type.ts +3 -3
  79. package/src/xml/excel-xml-drawing.ts +2 -2
  80. package/src/xml/excel-xml-relationship.ts +3 -3
  81. package/src/xml/excel-xml-shared-string.ts +2 -2
  82. package/src/xml/excel-xml-style.ts +13 -13
  83. package/src/xml/excel-xml-unknown.ts +2 -2
  84. package/src/xml/excel-xml-workbook.ts +14 -6
  85. package/src/xml/excel-xml-worksheet.ts +43 -43
  86. package/docs/core-classes.md +0 -541
  87. package/docs/utilities.md +0 -128
  88. package/tests/excel-cell.spec.ts +0 -393
  89. package/tests/excel-col.spec.ts +0 -81
  90. package/tests/excel-row.spec.ts +0 -61
  91. package/tests/excel-workbook.spec.ts +0 -205
  92. package/tests/excel-worksheet.spec.ts +0 -469
  93. package/tests/excel-wrapper.spec.ts +0 -273
  94. package/tests/fixtures/logo.png +0 -0
  95. package/tests/fixtures//354/264/210/352/270/260/355/231/224.xlsx +0 -0
  96. package/tests/image-insert.spec.ts +0 -190
  97. package/tests/utils/excel-utils.spec.ts +0 -198
@@ -1,393 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { ExcelWorkbook } from "../src/excel-workbook";
3
- import { ExcelXmlWorksheet } from "../src/xml/excel-xml-worksheet";
4
- import { DateOnly, DateTime, Time } from "@simplysm/core-common";
5
- import type { ExcelCellData, ExcelCellType } from "../src";
6
-
7
- describe("ExcelXmlWorksheet.getCellVal - inline string", () => {
8
- it("should read plain string inline text (no attributes)", () => {
9
- const ws = new ExcelXmlWorksheet({
10
- worksheet: {
11
- $: { xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main" },
12
- sheetData: [{
13
- row: [{
14
- $: { r: "1" },
15
- c: [{
16
- $: { r: "A1", t: "inlineStr" },
17
- is: [{ t: ["ID"] }],
18
- }],
19
- }],
20
- }],
21
- },
22
- });
23
-
24
- expect(ws.getCellVal({ r: 0, c: 0 })).toBe("ID");
25
- });
26
-
27
- it("should read object-form inline text (with attributes)", () => {
28
- const ws = new ExcelXmlWorksheet({
29
- worksheet: {
30
- $: { xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main" },
31
- sheetData: [{
32
- row: [{
33
- $: { r: "1" },
34
- c: [{
35
- $: { r: "A1", t: "inlineStr" },
36
- is: [{ t: [{ _: "Hello" }] }],
37
- }],
38
- }],
39
- }],
40
- },
41
- });
42
-
43
- expect(ws.getCellVal({ r: 0, c: 0 })).toBe("Hello");
44
- });
45
- });
46
-
47
- describe("ExcelCell", () => {
48
- describe("Cell Value Read/Write - Basic Types", () => {
49
- it("Can read and write string values", async () => {
50
- const wb = new ExcelWorkbook();
51
- const ws = await wb.addWorksheet("Test");
52
-
53
- await ws.cell(0, 0).setValue("Hello World");
54
- const val = await ws.cell(0, 0).getValue();
55
-
56
- expect(val).toBe("Hello World");
57
- });
58
-
59
- it("Can read and write number values", async () => {
60
- const wb = new ExcelWorkbook();
61
- const ws = await wb.addWorksheet("Test");
62
-
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);
67
-
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);
72
- });
73
-
74
- it("Can read and write boolean values", async () => {
75
- const wb = new ExcelWorkbook();
76
- const ws = await wb.addWorksheet("Test");
77
-
78
- await ws.cell(0, 0).setValue(true);
79
- await ws.cell(0, 1).setValue(false);
80
-
81
- expect(await ws.cell(0, 0).getValue()).toBe(true);
82
- expect(await ws.cell(0, 1).getValue()).toBe(false);
83
- });
84
-
85
- it("Setting undefined value deletes the cell", async () => {
86
- const wb = new ExcelWorkbook();
87
- const ws = await wb.addWorksheet("Test");
88
-
89
- await ws.cell(0, 0).setValue("Initial");
90
- expect(await ws.cell(0, 0).getValue()).toBe("Initial");
91
-
92
- await ws.cell(0, 0).setValue(undefined);
93
- expect(await ws.cell(0, 0).getValue()).toBeUndefined();
94
- });
95
-
96
- it("Throws error when setting unsupported type", async () => {
97
- const wb = new ExcelWorkbook();
98
- const ws = await wb.addWorksheet("Test");
99
-
100
- await expect(ws.cell(0, 0).setValue({} as any)).rejects.toThrow("Unsupported type");
101
-
102
- await expect(ws.cell(0, 1).setValue([] as any)).rejects.toThrow("Unsupported type");
103
- });
104
- });
105
-
106
- describe("Cell Value Read/Write - Date/Time Types", () => {
107
- it("Can read and write DateOnly values", async () => {
108
- const wb = new ExcelWorkbook();
109
- const ws = await wb.addWorksheet("Test");
110
-
111
- const date = new DateOnly(2024, 6, 15);
112
- await ws.cell(0, 0).setValue(date);
113
-
114
- const val = await ws.cell(0, 0).getValue();
115
- expect(val).toBeInstanceOf(DateOnly);
116
- expect((val as DateOnly).year).toBe(2024);
117
- expect((val as DateOnly).month).toBe(6);
118
- expect((val as DateOnly).day).toBe(15);
119
- });
120
-
121
- it("Can read and write DateTime values", async () => {
122
- const wb = new ExcelWorkbook();
123
- const ws = await wb.addWorksheet("Test");
124
-
125
- const dateTime = new DateTime(2024, 6, 15, 14, 30, 45);
126
- await ws.cell(0, 0).setValue(dateTime);
127
-
128
- const val = await ws.cell(0, 0).getValue();
129
- expect(val).toBeInstanceOf(DateTime);
130
- expect((val as DateTime).year).toBe(2024);
131
- expect((val as DateTime).month).toBe(6);
132
- expect((val as DateTime).day).toBe(15);
133
- expect((val as DateTime).hour).toBe(14);
134
- expect((val as DateTime).minute).toBe(30);
135
- expect((val as DateTime).second).toBe(45);
136
- });
137
-
138
- it("Can read and write Time values", async () => {
139
- const wb = new ExcelWorkbook();
140
- const ws = await wb.addWorksheet("Test");
141
-
142
- const time = new Time(14, 30, 45);
143
- await ws.cell(0, 0).setValue(time);
144
-
145
- const val = await ws.cell(0, 0).getValue();
146
- expect(val).toBeInstanceOf(Time);
147
- expect((val as Time).hour).toBe(14);
148
- expect((val as Time).minute).toBe(30);
149
- expect((val as Time).second).toBe(45);
150
- });
151
-
152
- it("DateOnly values persist after round-trip", async () => {
153
- const wb = new ExcelWorkbook();
154
- const ws = await wb.addWorksheet("Test");
155
-
156
- const date = new DateOnly(2024, 6, 15);
157
- await ws.cell(0, 0).setValue(date);
158
-
159
- const bytes = await wb.toBytes();
160
- await wb.close();
161
-
162
- const wb2 = new ExcelWorkbook(bytes);
163
- const ws2 = await wb2.getWorksheet(0);
164
-
165
- const val = await ws2.cell(0, 0).getValue();
166
- expect(val).toBeInstanceOf(DateOnly);
167
- expect((val as DateOnly).year).toBe(2024);
168
- expect((val as DateOnly).month).toBe(6);
169
- expect((val as DateOnly).day).toBe(15);
170
- await wb2.close();
171
- });
172
-
173
- it("DateTime values persist after round-trip", async () => {
174
- const wb = new ExcelWorkbook();
175
- const ws = await wb.addWorksheet("Test");
176
-
177
- const dateTime = new DateTime(2024, 6, 15, 14, 30, 45);
178
- await ws.cell(0, 0).setValue(dateTime);
179
-
180
- const bytes = await wb.toBytes();
181
- await wb.close();
182
-
183
- const wb2 = new ExcelWorkbook(bytes);
184
- const ws2 = await wb2.getWorksheet(0);
185
-
186
- const val = await ws2.cell(0, 0).getValue();
187
- expect(val).toBeInstanceOf(DateTime);
188
- expect((val as DateTime).year).toBe(2024);
189
- expect((val as DateTime).month).toBe(6);
190
- expect((val as DateTime).day).toBe(15);
191
- expect((val as DateTime).hour).toBe(14);
192
- expect((val as DateTime).minute).toBe(30);
193
- expect((val as DateTime).second).toBe(45);
194
- await wb2.close();
195
- });
196
-
197
- it("Time values persist after round-trip", async () => {
198
- const wb = new ExcelWorkbook();
199
- const ws = await wb.addWorksheet("Test");
200
-
201
- const time = new Time(14, 30, 45);
202
- await ws.cell(0, 0).setValue(time);
203
-
204
- const bytes = await wb.toBytes();
205
- await wb.close();
206
-
207
- const wb2 = new ExcelWorkbook(bytes);
208
- const ws2 = await wb2.getWorksheet(0);
209
-
210
- const val = await ws2.cell(0, 0).getValue();
211
- expect(val).toBeInstanceOf(Time);
212
- expect((val as Time).hour).toBe(14);
213
- expect((val as Time).minute).toBe(30);
214
- expect((val as Time).second).toBe(45);
215
- await wb2.close();
216
- });
217
- });
218
-
219
- describe("Formulas", () => {
220
- it("Can set formulas", async () => {
221
- const wb = new ExcelWorkbook();
222
- const ws = await wb.addWorksheet("Test");
223
-
224
- await ws.cell(0, 0).setValue(10);
225
- await ws.cell(0, 1).setValue(20);
226
- await ws.cell(0, 2).setFormula("A1+B1");
227
-
228
- // Verify formula directly
229
- const formula = await ws.cell(0, 2).getFormula();
230
- expect(formula).toBe("A1+B1");
231
-
232
- // Also verify with round-trip
233
- const buffer = await wb.toBytes();
234
-
235
- const wb2 = new ExcelWorkbook(buffer);
236
- const ws2 = await wb2.getWorksheet(0);
237
- // Formula exists but value must be calculated by Excel
238
- expect(ws2).toBeDefined();
239
- });
240
-
241
- it("Formulas persist after round-trip", async () => {
242
- const wb = new ExcelWorkbook();
243
- const ws = await wb.addWorksheet("Test");
244
-
245
- await ws.cell(0, 0).setValue(10);
246
- await ws.cell(0, 1).setValue(20);
247
- await ws.cell(0, 2).setFormula("SUM(A1:B1)");
248
-
249
- const buffer = await wb.toBytes();
250
- await wb.close();
251
-
252
- const wb2 = new ExcelWorkbook(buffer);
253
- const ws2 = await wb2.getWorksheet(0);
254
-
255
- // Verify that formula string is saved
256
- const formula = await ws2.cell(0, 2).getFormula();
257
- expect(formula).toBe("SUM(A1:B1)");
258
- await wb2.close();
259
- });
260
-
261
- it("Setting formula to undefined deletes it", async () => {
262
- const wb = new ExcelWorkbook();
263
- const ws = await wb.addWorksheet("Test");
264
-
265
- await ws.cell(0, 0).setFormula("A1+B1");
266
- await ws.cell(0, 0).setFormula(undefined);
267
-
268
- expect(await ws.cell(0, 0).getValue()).toBeUndefined();
269
- });
270
- });
271
-
272
- describe("Cell Merge", () => {
273
- it("Can merge cells", async () => {
274
- const wb = new ExcelWorkbook();
275
- const ws = await wb.addWorksheet("Test");
276
-
277
- await ws.cell(0, 0).setValue("Merged");
278
- await ws.cell(0, 0).merge(2, 3); // Merge 2 rows x 3 columns
279
-
280
- // Verify merge with round-trip
281
- const buffer = await wb.toBytes();
282
- const wb2 = new ExcelWorkbook(buffer);
283
- const ws2 = await wb2.getWorksheet(0);
284
-
285
- const val = await ws2.cell(0, 0).getValue();
286
- expect(val).toBe("Merged");
287
- });
288
-
289
- it("Throws error when attempting to merge overlapping ranges", async () => {
290
- const wb = new ExcelWorkbook();
291
- const ws = await wb.addWorksheet("Test");
292
-
293
- await ws.cell(0, 0).merge(2, 2); // Merge A1:B2
294
-
295
- // Attempt to merge overlapping range (B2:C3)
296
- await expect(ws.cell(1, 1).merge(2, 2)).rejects.toThrow("Merged cell overlaps with existing merge range");
297
- });
298
- });
299
-
300
- describe("Cell Style", () => {
301
- it("Can set multiple styles simultaneously", async () => {
302
- const wb = new ExcelWorkbook();
303
- const ws = await wb.addWorksheet("Test");
304
-
305
- await ws.cell(0, 0).setValue("Multi-Style");
306
- await ws.cell(0, 0).setStyle({
307
- background: "00FFFF00",
308
- border: ["left", "right"],
309
- horizontalAlign: "center",
310
- verticalAlign: "top",
311
- });
312
-
313
- const styleId = await ws.cell(0, 0).getStyleId();
314
- expect(styleId).toBeDefined();
315
- });
316
-
317
- it("Throws error for invalid color format", async () => {
318
- const wb = new ExcelWorkbook();
319
- const ws = await wb.addWorksheet("Test");
320
-
321
- await ws.cell(0, 0).setValue("Test");
322
- await expect(ws.cell(0, 0).setStyle({ background: "invalid" })).rejects.toThrow();
323
- });
324
-
325
- it("Styles persist after round-trip", async () => {
326
- const wb = new ExcelWorkbook();
327
- const ws = await wb.addWorksheet("Test");
328
-
329
- // Set various styles
330
- await ws.cell(0, 0).setValue("Styled");
331
- await ws.cell(0, 0).setStyle({
332
- background: "00FF0000", // Red
333
- border: ["left", "right", "top", "bottom"],
334
- horizontalAlign: "center",
335
- verticalAlign: "top",
336
- });
337
-
338
- const bytes = await wb.toBytes();
339
-
340
- // Verify styles after round-trip
341
- const wb2 = new ExcelWorkbook(bytes);
342
- const ws2 = await wb2.getWorksheet("Test");
343
-
344
- // Verify value
345
- const val = await ws2.cell(0, 0).getValue();
346
- expect(val).toBe("Styled");
347
-
348
- // Verify style ID exists
349
- const styleId = await ws2.cell(0, 0).getStyleId();
350
- expect(styleId).toBeDefined();
351
-
352
- // Verify style data at XML level
353
- const styleData = await (wb2 as any).zipCache.get("xl/styles.xml");
354
- const styleIdNum = parseInt(styleId!, 10);
355
- const xf = styleData.data.styleSheet.cellXfs[0].xf[styleIdNum];
356
-
357
- // Verify background color
358
- expect(xf.$.fillId).toBeDefined();
359
- const fillId = parseInt(xf.$.fillId, 10);
360
- const fill = styleData.data.styleSheet.fills[0].fill[fillId];
361
- expect(fill.patternFill[0].fgColor[0].$.rgb).toBe("00FF0000");
362
-
363
- // Verify borders
364
- expect(xf.$.borderId).toBeDefined();
365
- const borderId = parseInt(xf.$.borderId, 10);
366
- const border = styleData.data.styleSheet.borders[0].border[borderId];
367
- expect(border.left).toBeDefined();
368
- expect(border.right).toBeDefined();
369
- expect(border.top).toBeDefined();
370
- expect(border.bottom).toBeDefined();
371
-
372
- // Verify alignment
373
- expect(xf.alignment).toBeDefined();
374
- expect(xf.alignment[0].$.horizontal).toBe("center");
375
- expect(xf.alignment[0].$.vertical).toBe("top");
376
- });
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
- });
@@ -1,81 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { ExcelWorkbook } from "../src/excel-workbook";
3
-
4
- describe("ExcelCol", () => {
5
- describe("cell()", () => {
6
- it("Returns cell corresponding to row index", async () => {
7
- const wb = new ExcelWorkbook();
8
- const ws = await wb.addWorksheet("Test");
9
-
10
- const col = ws.col(0);
11
- const cell = col.cell(0);
12
-
13
- await cell.setValue("Hello");
14
- expect(await cell.getValue()).toBe("Hello");
15
- });
16
-
17
- it("Returns same instance for same index (caching)", async () => {
18
- const wb = new ExcelWorkbook();
19
- const ws = await wb.addWorksheet("Test");
20
-
21
- const col = ws.col(0);
22
- const cell1 = col.cell(0);
23
- const cell2 = col.cell(0);
24
-
25
- expect(cell1).toBe(cell2);
26
- });
27
-
28
- });
29
-
30
- describe("getCells()", () => {
31
- it("Returns all cells within range", async () => {
32
- const wb = new ExcelWorkbook();
33
- const ws = await wb.addWorksheet("Test");
34
-
35
- // Set data to define range
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
-
40
- const col = ws.col(0);
41
- const cells = await col.getCells();
42
-
43
- expect(cells.length).toBeGreaterThanOrEqual(3);
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
- });
48
-
49
- it("Returns cell corresponding to default range (0,0) from empty worksheet", async () => {
50
- const wb = new ExcelWorkbook();
51
- const ws = await wb.addWorksheet("Test");
52
-
53
- const col = ws.col(0);
54
- const cells = await col.getCells();
55
-
56
- // Default range of empty worksheet is (0,0)-(0,0), so returns one cell
57
- expect(cells.length).toBe(1);
58
- expect(await cells[0].getValue()).toBeUndefined();
59
- });
60
- });
61
-
62
- describe("setWidth()", () => {
63
- it("Can set column width", async () => {
64
- const wb = new ExcelWorkbook();
65
- const ws = await wb.addWorksheet("Test");
66
-
67
- // Add data and set width
68
- await ws.cell(0, 0).setValue("Test");
69
- await ws.col(0).setWidth(20);
70
-
71
- // Verify settings via round-trip
72
- const bytes = await wb.toBytes();
73
- const wb2 = new ExcelWorkbook(bytes);
74
- const ws2 = await wb2.getWorksheet(0);
75
-
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).getValue()).toBe("Test");
78
- });
79
-
80
- });
81
- });
@@ -1,61 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { ExcelWorkbook } from "../src/excel-workbook";
3
-
4
- describe("ExcelRow", () => {
5
- describe("cell()", () => {
6
- it("returns cell corresponding to column index", async () => {
7
- const wb = new ExcelWorkbook();
8
- const ws = await wb.addWorksheet("Test");
9
-
10
- const row = ws.row(0);
11
- const cell = row.cell(0);
12
-
13
- await cell.setValue("Hello");
14
- expect(await cell.getValue()).toBe("Hello");
15
- });
16
-
17
- it("returns same instance for same index (caching)", async () => {
18
- const wb = new ExcelWorkbook();
19
- const ws = await wb.addWorksheet("Test");
20
-
21
- const row = ws.row(0);
22
- const cell1 = row.cell(0);
23
- const cell2 = row.cell(0);
24
-
25
- expect(cell1).toBe(cell2);
26
- });
27
-
28
- });
29
-
30
- describe("getCells()", () => {
31
- it("returns all cells within range", async () => {
32
- const wb = new ExcelWorkbook();
33
- const ws = await wb.addWorksheet("Test");
34
-
35
- // Set range by configuring data
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
-
40
- const row = ws.row(0);
41
- const cells = await row.getCells();
42
-
43
- expect(cells.length).toBeGreaterThanOrEqual(3);
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
- });
48
-
49
- it("returns cell corresponding to default range (0,0) in empty worksheet", async () => {
50
- const wb = new ExcelWorkbook();
51
- const ws = await wb.addWorksheet("Test");
52
-
53
- const row = ws.row(0);
54
- const cells = await row.getCells();
55
-
56
- // Empty worksheet default range is (0,0)-(0,0) so returns one cell
57
- expect(cells.length).toBe(1);
58
- expect(await cells[0].getValue()).toBeUndefined();
59
- });
60
- });
61
- });