@simplysm/excel 13.0.99 → 14.0.1
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/dist/excel-cell.d.ts +28 -28
- package/dist/excel-cell.d.ts.map +1 -1
- package/dist/excel-cell.js +273 -264
- package/dist/excel-cell.js.map +1 -6
- package/dist/excel-col.d.ts +4 -4
- package/dist/excel-col.d.ts.map +1 -1
- package/dist/excel-col.js +33 -35
- package/dist/excel-col.js.map +1 -6
- package/dist/excel-row.d.ts +3 -3
- package/dist/excel-row.d.ts.map +1 -1
- package/dist/excel-row.js +28 -30
- package/dist/excel-row.js.map +1 -6
- package/dist/excel-workbook.d.ts +23 -23
- package/dist/excel-workbook.d.ts.map +1 -1
- package/dist/excel-workbook.js +151 -125
- package/dist/excel-workbook.js.map +1 -6
- package/dist/excel-worksheet.d.ts +32 -32
- package/dist/excel-worksheet.d.ts.map +1 -1
- package/dist/excel-worksheet.js +281 -253
- package/dist/excel-worksheet.js.map +1 -6
- package/dist/excel-wrapper.d.ts +7 -7
- package/dist/excel-wrapper.d.ts.map +1 -1
- package/dist/excel-wrapper.js +190 -226
- package/dist/excel-wrapper.js.map +1 -6
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -6
- package/dist/types.d.ts +13 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -1
- package/dist/types.js.map +1 -6
- package/dist/utils/excel-utils.d.ts +23 -23
- package/dist/utils/excel-utils.d.ts.map +1 -1
- package/dist/utils/excel-utils.js +183 -151
- package/dist/utils/excel-utils.js.map +1 -6
- package/dist/utils/zip-cache.d.ts +6 -6
- package/dist/utils/zip-cache.js +78 -60
- package/dist/utils/zip-cache.js.map +1 -6
- package/dist/xml/excel-xml-content-type.d.ts +2 -2
- package/dist/xml/excel-xml-content-type.js +55 -53
- package/dist/xml/excel-xml-content-type.js.map +1 -6
- package/dist/xml/excel-xml-drawing.d.ts +2 -2
- package/dist/xml/excel-xml-drawing.js +74 -73
- package/dist/xml/excel-xml-drawing.js.map +1 -6
- package/dist/xml/excel-xml-relationship.d.ts +2 -2
- package/dist/xml/excel-xml-relationship.js +67 -67
- package/dist/xml/excel-xml-relationship.js.map +1 -6
- package/dist/xml/excel-xml-shared-string.d.ts +2 -2
- package/dist/xml/excel-xml-shared-string.js +57 -55
- package/dist/xml/excel-xml-shared-string.js.map +1 -6
- package/dist/xml/excel-xml-style.d.ts +2 -2
- package/dist/xml/excel-xml-style.js +311 -295
- package/dist/xml/excel-xml-style.js.map +1 -6
- package/dist/xml/excel-xml-unknown.d.ts +2 -2
- package/dist/xml/excel-xml-unknown.js +11 -10
- package/dist/xml/excel-xml-unknown.js.map +1 -6
- package/dist/xml/excel-xml-workbook.d.ts +2 -2
- package/dist/xml/excel-xml-workbook.js +87 -90
- package/dist/xml/excel-xml-workbook.js.map +1 -6
- package/dist/xml/excel-xml-worksheet.d.ts +6 -6
- package/dist/xml/excel-xml-worksheet.js +450 -393
- package/dist/xml/excel-xml-worksheet.js.map +1 -6
- package/package.json +5 -7
- package/src/excel-cell.ts +36 -36
- package/src/excel-col.ts +4 -4
- package/src/excel-row.ts +3 -3
- package/src/excel-workbook.ts +38 -38
- package/src/excel-worksheet.ts +69 -51
- package/src/excel-wrapper.ts +55 -50
- package/src/index.ts +3 -3
- package/src/types.ts +17 -17
- package/src/utils/excel-utils.ts +47 -41
- package/src/utils/zip-cache.ts +6 -6
- package/src/xml/excel-xml-content-type.ts +3 -3
- package/src/xml/excel-xml-drawing.ts +2 -2
- package/src/xml/excel-xml-relationship.ts +3 -3
- package/src/xml/excel-xml-shared-string.ts +2 -2
- package/src/xml/excel-xml-style.ts +11 -11
- package/src/xml/excel-xml-unknown.ts +2 -2
- package/src/xml/excel-xml-workbook.ts +5 -5
- package/src/xml/excel-xml-worksheet.ts +43 -43
- package/README.md +0 -119
- package/docs/core-classes.md +0 -541
- package/docs/types.md +0 -297
- package/docs/utilities.md +0 -128
- package/docs/wrapper.md +0 -100
- package/tests/excel-cell.spec.ts +0 -393
- package/tests/excel-col.spec.ts +0 -81
- package/tests/excel-row.spec.ts +0 -61
- package/tests/excel-workbook.spec.ts +0 -205
- package/tests/excel-worksheet.spec.ts +0 -469
- package/tests/excel-wrapper.spec.ts +0 -273
- package/tests/fixtures/logo.png +0 -0
- package/tests/fixtures//354/264/210/352/270/260/355/231/224.xlsx +0 -0
- package/tests/image-insert.spec.ts +0 -190
- package/tests/utils/excel-utils.spec.ts +0 -198
package/docs/types.md
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
# Types
|
|
2
|
-
|
|
3
|
-
All type exports from the excel package.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
import type {
|
|
7
|
-
ExcelValueType,
|
|
8
|
-
ExcelNumberFormat,
|
|
9
|
-
ExcelCellType,
|
|
10
|
-
ExcelAddressPoint,
|
|
11
|
-
ExcelAddressRangePoint,
|
|
12
|
-
ExcelStyleOptions,
|
|
13
|
-
ExcelBorderPosition,
|
|
14
|
-
ExcelHorizontalAlign,
|
|
15
|
-
ExcelVerticalAlign,
|
|
16
|
-
ExcelXml,
|
|
17
|
-
// XML data types (internal)
|
|
18
|
-
ExcelXmlContentTypeData,
|
|
19
|
-
ExcelXmlRelationshipData,
|
|
20
|
-
ExcelXmlWorkbookData,
|
|
21
|
-
ExcelXmlWorksheetData,
|
|
22
|
-
ExcelRowData,
|
|
23
|
-
ExcelCellData,
|
|
24
|
-
ExcelXmlDrawingData,
|
|
25
|
-
ExcelXmlSharedStringData,
|
|
26
|
-
ExcelXmlSharedStringDataSi,
|
|
27
|
-
ExcelXmlSharedStringDataText,
|
|
28
|
-
ExcelXmlStyleData,
|
|
29
|
-
ExcelXmlStyleDataXf,
|
|
30
|
-
ExcelXmlStyleDataFill,
|
|
31
|
-
ExcelXmlStyleDataBorder,
|
|
32
|
-
} from "@simplysm/excel";
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Value Types
|
|
36
|
-
|
|
37
|
-
### `ExcelValueType`
|
|
38
|
-
|
|
39
|
-
Union of supported cell value types.
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
type ExcelValueType = number | string | DateOnly | DateTime | Time | boolean | undefined;
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### `ExcelNumberFormat`
|
|
46
|
-
|
|
47
|
-
Number format name.
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
type ExcelNumberFormat = "number" | "string" | "DateOnly" | "DateTime" | "Time";
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### `ExcelCellType`
|
|
54
|
-
|
|
55
|
-
Excel cell type identifier.
|
|
56
|
-
|
|
57
|
-
```typescript
|
|
58
|
-
type ExcelCellType = "s" | "b" | "str" | "n" | "inlineStr" | "e";
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
- `s` -- shared string (SharedString)
|
|
62
|
-
- `b` -- boolean
|
|
63
|
-
- `str` -- formula result string
|
|
64
|
-
- `n` -- number
|
|
65
|
-
- `inlineStr` -- inline string (rich text)
|
|
66
|
-
- `e` -- error
|
|
67
|
-
|
|
68
|
-
## Address Types
|
|
69
|
-
|
|
70
|
-
### `ExcelAddressPoint`
|
|
71
|
-
|
|
72
|
-
Cell coordinate (0-based).
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
interface ExcelAddressPoint {
|
|
76
|
-
r: number;
|
|
77
|
-
c: number;
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### `ExcelAddressRangePoint`
|
|
82
|
-
|
|
83
|
-
Range of cell coordinates (start and end).
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
interface ExcelAddressRangePoint {
|
|
87
|
-
s: ExcelAddressPoint;
|
|
88
|
-
e: ExcelAddressPoint;
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## Style Types
|
|
93
|
-
|
|
94
|
-
### `ExcelBorderPosition`
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
type ExcelBorderPosition = "left" | "right" | "top" | "bottom";
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### `ExcelHorizontalAlign`
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
type ExcelHorizontalAlign = "center" | "left" | "right";
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### `ExcelVerticalAlign`
|
|
107
|
-
|
|
108
|
-
```typescript
|
|
109
|
-
type ExcelVerticalAlign = "center" | "top" | "bottom";
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### `ExcelStyleOptions`
|
|
113
|
-
|
|
114
|
-
Cell style options.
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
interface ExcelStyleOptions {
|
|
118
|
-
/** Background color (ARGB format, e.g. "00FF0000") */
|
|
119
|
-
background?: string;
|
|
120
|
-
/** Border positions */
|
|
121
|
-
border?: ExcelBorderPosition[];
|
|
122
|
-
/** Horizontal alignment */
|
|
123
|
-
horizontalAlign?: ExcelHorizontalAlign;
|
|
124
|
-
/** Vertical alignment */
|
|
125
|
-
verticalAlign?: ExcelVerticalAlign;
|
|
126
|
-
/** Number format */
|
|
127
|
-
numberFormat?: ExcelNumberFormat;
|
|
128
|
-
}
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
**Example:**
|
|
132
|
-
```typescript
|
|
133
|
-
await cell.setStyle({
|
|
134
|
-
background: "00FF0000",
|
|
135
|
-
border: ["left", "right", "top", "bottom"],
|
|
136
|
-
horizontalAlign: "center",
|
|
137
|
-
verticalAlign: "center",
|
|
138
|
-
numberFormat: "number",
|
|
139
|
-
});
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## Excel XML Interface
|
|
143
|
-
|
|
144
|
-
### `ExcelXml`
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
interface ExcelXml {
|
|
148
|
-
readonly data: unknown;
|
|
149
|
-
cleanup(): void;
|
|
150
|
-
}
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
## XML Data Types
|
|
154
|
-
|
|
155
|
-
These types represent the internal XML structure of `.xlsx` files. They are used internally by the library but exported for advanced use cases.
|
|
156
|
-
|
|
157
|
-
### `ExcelXmlContentTypeData`
|
|
158
|
-
|
|
159
|
-
Content type definitions (`[Content_Types].xml`).
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
interface ExcelXmlContentTypeData {
|
|
163
|
-
Types: {
|
|
164
|
-
$: { xmlns: string };
|
|
165
|
-
Default: { $: { Extension: string; ContentType: string } }[];
|
|
166
|
-
Override: { $: { PartName: string; ContentType: string } }[];
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### `ExcelXmlRelationshipData`
|
|
172
|
-
|
|
173
|
-
Relationship definitions (`.rels` files).
|
|
174
|
-
|
|
175
|
-
```typescript
|
|
176
|
-
interface ExcelXmlRelationshipData {
|
|
177
|
-
Relationships: {
|
|
178
|
-
$: { xmlns: string };
|
|
179
|
-
Relationship?: ExcelRelationshipData[];
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
### `ExcelXmlWorkbookData`
|
|
185
|
-
|
|
186
|
-
Workbook XML data.
|
|
187
|
-
|
|
188
|
-
```typescript
|
|
189
|
-
interface ExcelXmlWorkbookData {
|
|
190
|
-
workbook: {
|
|
191
|
-
$: { "xmlns": string; "xmlns:r"?: string };
|
|
192
|
-
bookViews?: [{ workbookView: [{}] }];
|
|
193
|
-
sheets?: [{ sheet: { $: { "name": string; "sheetId": string; "r:id": string } }[] }];
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### `ExcelXmlWorksheetData`
|
|
199
|
-
|
|
200
|
-
Worksheet XML data. Contains sheet data, dimensions, views, columns, merge cells, and drawing references.
|
|
201
|
-
|
|
202
|
-
### `ExcelRowData`
|
|
203
|
-
|
|
204
|
-
```typescript
|
|
205
|
-
interface ExcelRowData {
|
|
206
|
-
$: { r: string }; // row address (1-based)
|
|
207
|
-
c?: ExcelCellData[];
|
|
208
|
-
}
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
### `ExcelCellData`
|
|
212
|
-
|
|
213
|
-
```typescript
|
|
214
|
-
interface ExcelCellData {
|
|
215
|
-
$: {
|
|
216
|
-
r: string; // cell address (e.g. "A1")
|
|
217
|
-
s?: string; // styleId
|
|
218
|
-
t?: ExcelCellType; // type
|
|
219
|
-
};
|
|
220
|
-
v?: [string]; // value
|
|
221
|
-
f?: [string]; // formula
|
|
222
|
-
is?: { t?: (string | { _?: string })[] }[]; // inline string
|
|
223
|
-
}
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
### `ExcelXmlDrawingData`
|
|
227
|
-
|
|
228
|
-
Drawing XML data (embedded images).
|
|
229
|
-
|
|
230
|
-
### `ExcelXmlSharedStringData`
|
|
231
|
-
|
|
232
|
-
Shared strings table.
|
|
233
|
-
|
|
234
|
-
```typescript
|
|
235
|
-
interface ExcelXmlSharedStringData {
|
|
236
|
-
sst: {
|
|
237
|
-
$: { xmlns: string };
|
|
238
|
-
si?: ExcelXmlSharedStringDataSi[];
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
### `ExcelXmlSharedStringDataSi`
|
|
244
|
-
|
|
245
|
-
```typescript
|
|
246
|
-
type ExcelXmlSharedStringDataSi =
|
|
247
|
-
| { t: ExcelXmlSharedStringDataText }
|
|
248
|
-
| { r: { t: ExcelXmlSharedStringDataText }[] };
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
### `ExcelXmlSharedStringDataText`
|
|
252
|
-
|
|
253
|
-
```typescript
|
|
254
|
-
type ExcelXmlSharedStringDataText = [
|
|
255
|
-
string | { $: { space?: "preserve" }; _?: string },
|
|
256
|
-
];
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
### `ExcelXmlStyleData`
|
|
260
|
-
|
|
261
|
-
Style definitions (styles.xml). Contains number formats, fonts, fills, borders, and cell formats.
|
|
262
|
-
|
|
263
|
-
### `ExcelXmlStyleDataXf`
|
|
264
|
-
|
|
265
|
-
Cell format definition.
|
|
266
|
-
|
|
267
|
-
```typescript
|
|
268
|
-
interface ExcelXmlStyleDataXf {
|
|
269
|
-
$: {
|
|
270
|
-
numFmtId?: string;
|
|
271
|
-
fontId?: string;
|
|
272
|
-
fillId?: string;
|
|
273
|
-
borderId?: string;
|
|
274
|
-
xfId?: string;
|
|
275
|
-
applyNumberFormat?: string;
|
|
276
|
-
applyFont?: string;
|
|
277
|
-
applyAlignment?: string;
|
|
278
|
-
applyFill?: string;
|
|
279
|
-
applyBorder?: string;
|
|
280
|
-
};
|
|
281
|
-
alignment?: [{ $: { horizontal?: "center" | "left" | "right"; vertical?: "center" | "top" | "bottom" } }];
|
|
282
|
-
}
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
### `ExcelXmlStyleDataFill`
|
|
286
|
-
|
|
287
|
-
Fill style definition.
|
|
288
|
-
|
|
289
|
-
```typescript
|
|
290
|
-
interface ExcelXmlStyleDataFill {
|
|
291
|
-
patternFill: [{ $: { patternType: "none" | "solid" | "gray125" }; fgColor?: [{ $: { rgb: string } }] }];
|
|
292
|
-
}
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
### `ExcelXmlStyleDataBorder`
|
|
296
|
-
|
|
297
|
-
Border style definition. Each side (`top`, `left`, `right`, `bottom`) has `style` (`"thin"` | `"medium"`) and optional `color`.
|
package/docs/utilities.md
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
# Utilities
|
|
2
|
-
|
|
3
|
-
## `ExcelUtils`
|
|
4
|
-
|
|
5
|
-
Collection of Excel utility functions. Provides cell address conversion, date/number conversion, and number format processing.
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { ExcelUtils } from "@simplysm/excel";
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
### Address Conversion
|
|
12
|
-
|
|
13
|
-
#### `stringifyAddr`
|
|
14
|
-
|
|
15
|
-
Convert cell coordinates to "A1" format string.
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
static stringifyAddr(point: ExcelAddressPoint): string;
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
#### `stringifyRowAddr`
|
|
22
|
-
|
|
23
|
-
Convert row index (0-based) to row address string (e.g. `0` -> `"1"`).
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
static stringifyRowAddr(r: number): string;
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
#### `stringifyColAddr`
|
|
30
|
-
|
|
31
|
-
Convert column index (0-based) to column address string (e.g. `0` -> `"A"`, `26` -> `"AA"`).
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
static stringifyColAddr(c: number): string;
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
**Throws:** `Error` if column index is outside range `0-16383`.
|
|
38
|
-
|
|
39
|
-
#### `parseRowAddr`
|
|
40
|
-
|
|
41
|
-
Extract row index from cell address (e.g. `"A3"` -> `2`).
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
static parseRowAddr(addr: string): number;
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
#### `parseColAddr`
|
|
48
|
-
|
|
49
|
-
Extract column index from cell address (e.g. `"B3"` -> `1`).
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
static parseColAddr(addr: string): number;
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
#### `parseCellAddr`
|
|
56
|
-
|
|
57
|
-
Convert cell address to coordinates (e.g. `"B3"` -> `{r: 2, c: 1}`).
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
static parseCellAddr(addr: string): ExcelAddressPoint;
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
#### `parseRangeAddr`
|
|
64
|
-
|
|
65
|
-
Convert range address to coordinates (e.g. `"A1:C3"` -> `{s: {r:0,c:0}, e: {r:2,c:2}}`).
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
static parseRangeAddr(rangeAddr: string): ExcelAddressRangePoint;
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
#### `stringifyRangeAddr`
|
|
72
|
-
|
|
73
|
-
Convert range coordinates to address string.
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
static stringifyRangeAddr(point: ExcelAddressRangePoint): string;
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Date/Number Conversion
|
|
80
|
-
|
|
81
|
-
#### `convertTimeTickToNumber`
|
|
82
|
-
|
|
83
|
-
Convert JavaScript timestamp (ms) to Excel date number. Excel counts 1900-01-01 as 1 (1899-12-30 is date 0).
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
static convertTimeTickToNumber(tick: number): number;
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
#### `convertNumberToTimeTick`
|
|
90
|
-
|
|
91
|
-
Convert Excel date number to JavaScript timestamp (ms).
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
static convertNumberToTimeTick(value: number): number;
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### Number Format
|
|
98
|
-
|
|
99
|
-
#### `convertNumFmtCodeToName`
|
|
100
|
-
|
|
101
|
-
Convert number format code to format name.
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
static convertNumFmtCodeToName(numFmtCode: string): ExcelNumberFormat;
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
#### `convertNumFmtIdToName`
|
|
108
|
-
|
|
109
|
-
Convert number format ID to format name.
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
static convertNumFmtIdToName(numFmtId: number): ExcelNumberFormat;
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Built-in format ID ranges:
|
|
116
|
-
- `0-13, 37-40, 48`: number/general/currency/percent formats
|
|
117
|
-
- `14-17, 27-31, 34-36, 50-58`: date formats (including localized)
|
|
118
|
-
- `22`: date+time format
|
|
119
|
-
- `18-21, 32-33, 45-47`: time formats
|
|
120
|
-
- `49`: text format
|
|
121
|
-
|
|
122
|
-
#### `convertNumFmtNameToId`
|
|
123
|
-
|
|
124
|
-
Convert number format name to format ID.
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
static convertNumFmtNameToId(numFmtName: ExcelNumberFormat): number;
|
|
128
|
-
```
|
package/docs/wrapper.md
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
# ExcelWrapper
|
|
2
|
-
|
|
3
|
-
Zod schema-based Excel wrapper. Infers type information from schema to provide type-safe read/write.
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
import { ExcelWrapper } from "@simplysm/excel";
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
## Class: `ExcelWrapper<TSchema>`
|
|
10
|
-
|
|
11
|
-
### Constructor
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
constructor(schema: TSchema)
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
- `schema` -- Zod object schema. Defines the record structure. Use `.describe()` on fields to specify Excel header names.
|
|
18
|
-
|
|
19
|
-
### `read`
|
|
20
|
-
|
|
21
|
-
Read Excel file into record array.
|
|
22
|
-
|
|
23
|
-
```typescript
|
|
24
|
-
async read(
|
|
25
|
-
file: Bytes | Blob,
|
|
26
|
-
wsNameOrIndex?: string | number,
|
|
27
|
-
options?: { excludes?: (keyof z.infer<TSchema>)[] },
|
|
28
|
-
): Promise<z.infer<TSchema>[]>;
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
**Parameters:**
|
|
32
|
-
- `file` -- Excel file data (Uint8Array or Blob)
|
|
33
|
-
- `wsNameOrIndex` -- Worksheet name or index (default: `0`)
|
|
34
|
-
- `options.excludes` -- Field keys to exclude from reading
|
|
35
|
-
|
|
36
|
-
Values are automatically converted based on the Zod schema type:
|
|
37
|
-
- `ZodString` -- converts to string
|
|
38
|
-
- `ZodNumber` -- converts to number
|
|
39
|
-
- `ZodBoolean` -- converts to boolean (`"1"`, `"true"` -> `true`)
|
|
40
|
-
- `DateOnly`, `DateTime`, `Time` -- preserved as-is from Excel
|
|
41
|
-
|
|
42
|
-
Each row is validated against the Zod schema. Rows where all values are empty are skipped.
|
|
43
|
-
|
|
44
|
-
### `write`
|
|
45
|
-
|
|
46
|
-
Record array to Excel workbook.
|
|
47
|
-
|
|
48
|
-
The caller is responsible for managing the returned workbook's resources. Use `await using` or call `close()` after use.
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
async write(
|
|
52
|
-
wsName: string,
|
|
53
|
-
records: Partial<z.infer<TSchema>>[],
|
|
54
|
-
options?: { excludes?: (keyof z.infer<TSchema>)[] },
|
|
55
|
-
): Promise<ExcelWorkbook>;
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
**Parameters:**
|
|
59
|
-
- `wsName` -- Worksheet name
|
|
60
|
-
- `records` -- Record array to write
|
|
61
|
-
- `options.excludes` -- Field keys to exclude from writing
|
|
62
|
-
|
|
63
|
-
**Behavior:**
|
|
64
|
-
- Headers are written in the first row using `.describe()` names (or field keys if no description)
|
|
65
|
-
- Data rows follow from row index 1
|
|
66
|
-
- All cells get border styling (`left`, `right`, `top`, `bottom`)
|
|
67
|
-
- Required field headers (non-optional, non-nullable, non-default, non-boolean) are highlighted in yellow (`00FFFF00`)
|
|
68
|
-
- Zoom is set to 85%
|
|
69
|
-
- First row is frozen
|
|
70
|
-
|
|
71
|
-
## Example
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
import { z } from "zod";
|
|
75
|
-
import { ExcelWrapper } from "@simplysm/excel";
|
|
76
|
-
|
|
77
|
-
const schema = z.object({
|
|
78
|
-
name: z.string().describe("Name"),
|
|
79
|
-
age: z.number().describe("Age"),
|
|
80
|
-
email: z.string().optional().describe("Email"),
|
|
81
|
-
active: z.boolean().default(false).describe("Active"),
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const wrapper = new ExcelWrapper(schema);
|
|
85
|
-
|
|
86
|
-
// Read Excel file
|
|
87
|
-
const records = await wrapper.read(fileBytes);
|
|
88
|
-
// records: { name: string; age: number; email?: string; active: boolean }[]
|
|
89
|
-
|
|
90
|
-
// Write to Excel
|
|
91
|
-
await using wb = await wrapper.write("Users", [
|
|
92
|
-
{ name: "Alice", age: 30, email: "alice@example.com" },
|
|
93
|
-
{ name: "Bob", age: 25 },
|
|
94
|
-
]);
|
|
95
|
-
const bytes = await wb.toBytes();
|
|
96
|
-
|
|
97
|
-
// Exclude specific fields
|
|
98
|
-
const records2 = await wrapper.read(fileBytes, 0, { excludes: ["email"] });
|
|
99
|
-
await using wb2 = await wrapper.write("Users", records2, { excludes: ["email"] });
|
|
100
|
-
```
|