@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.
- package/README.md +66 -78
- 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 +3 -2
- package/dist/xml/excel-xml-workbook.d.ts.map +1 -1
- package/dist/xml/excel-xml-workbook.js +95 -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/docs/core.md +147 -0
- package/docs/types.md +201 -212
- package/docs/wrapper.md +32 -62
- package/package.json +8 -6
- 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 +13 -13
- package/src/xml/excel-xml-unknown.ts +2 -2
- package/src/xml/excel-xml-workbook.ts +14 -6
- package/src/xml/excel-xml-worksheet.ts +43 -43
- package/docs/core-classes.md +0 -541
- package/docs/utilities.md +0 -128
- 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
CHANGED
|
@@ -1,297 +1,286 @@
|
|
|
1
|
-
# Types
|
|
1
|
+
# Types & Utilities
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Types, enums, and utility functions for Excel file processing.
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
```
|
|
5
|
+
## XML Data Types
|
|
34
6
|
|
|
35
|
-
|
|
7
|
+
Internal XML structure types used by the library to represent .xlsx file contents.
|
|
36
8
|
|
|
37
|
-
###
|
|
9
|
+
### ExcelXmlContentTypeData
|
|
38
10
|
|
|
39
|
-
|
|
11
|
+
Represents `[Content_Types].xml` in the .xlsx archive.
|
|
40
12
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
13
|
+
| Field | Type | Description |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| `Types.$` | `{ xmlns: string }` | XML namespace |
|
|
16
|
+
| `Types.Default` | `Array<{ $: { Extension: string; ContentType: string } }>` | Default content type mappings by file extension |
|
|
17
|
+
| `Types.Override` | `Array<{ $: { PartName: string; ContentType: string } }>` | Override content type mappings by part name |
|
|
44
18
|
|
|
45
|
-
###
|
|
19
|
+
### ExcelXmlRelationshipData
|
|
46
20
|
|
|
47
|
-
|
|
21
|
+
Represents a `_rels/*.rels` relationship file.
|
|
48
22
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
23
|
+
| Field | Type | Description |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| `Relationships.$` | `{ xmlns: string }` | XML namespace |
|
|
26
|
+
| `Relationships.Relationship?` | `ExcelRelationshipData[]` | Array of relationship entries |
|
|
52
27
|
|
|
53
|
-
###
|
|
28
|
+
### ExcelRelationshipData
|
|
54
29
|
|
|
55
|
-
|
|
30
|
+
A single relationship entry.
|
|
56
31
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
32
|
+
| Field | Type | Description |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| `$.Id` | `string` | Relationship ID (e.g., "rId1") |
|
|
35
|
+
| `$.Target` | `string` | Target path |
|
|
36
|
+
| `$.Type` | `string` | Relationship type URI |
|
|
60
37
|
|
|
61
|
-
|
|
62
|
-
- `b` -- boolean
|
|
63
|
-
- `str` -- formula result string
|
|
64
|
-
- `n` -- number
|
|
65
|
-
- `inlineStr` -- inline string (rich text)
|
|
66
|
-
- `e` -- error
|
|
38
|
+
### ExcelXmlWorkbookData
|
|
67
39
|
|
|
68
|
-
|
|
40
|
+
Represents `xl/workbook.xml`.
|
|
69
41
|
|
|
70
|
-
|
|
42
|
+
| Field | Type | Description |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
| `workbook.$` | `{ xmlns: string; "xmlns:r"?: string }` | XML namespaces |
|
|
45
|
+
| `workbook.bookViews?` | `[{ workbookView: [{}] }]` | Workbook view settings |
|
|
46
|
+
| `workbook.sheets?` | `[{ sheet: Array<{ $: { name: string; sheetId: string; "r:id": string } }> }]` | Sheet definitions |
|
|
71
47
|
|
|
72
|
-
|
|
48
|
+
### ExcelXmlWorksheetData
|
|
73
49
|
|
|
74
|
-
|
|
75
|
-
interface ExcelAddressPoint {
|
|
76
|
-
r: number;
|
|
77
|
-
c: number;
|
|
78
|
-
}
|
|
79
|
-
```
|
|
50
|
+
Represents `xl/worksheets/sheet*.xml`.
|
|
80
51
|
|
|
81
|
-
|
|
52
|
+
| Field | Type | Description |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| `worksheet.$` | `{ xmlns: string; "xmlns:r"?: string }` | XML namespaces |
|
|
55
|
+
| `worksheet.dimension?` | `[{ $: { ref: string } }]` | Used range reference (e.g., "A1:C10") |
|
|
56
|
+
| `worksheet.sheetViews?` | See source | Sheet view settings (zoom, freeze panes) |
|
|
57
|
+
| `worksheet.sheetFormatPr?` | `[{ $: { defaultRowHeight: string } }]` | Default row height |
|
|
58
|
+
| `worksheet.cols?` | `[{ col: Array<{ $: { min: string; max: string; width?: string; bestFit?: string; customWidth?: string } }> }]` | Column width definitions |
|
|
59
|
+
| `worksheet.sheetData` | `[{ row?: ExcelRowData[] }]` | Row data (required) |
|
|
60
|
+
| `worksheet.mergeCells?` | `[{ $: { count: string }; mergeCell: Array<{ $: { ref: string } }> }]` | Merged cell ranges |
|
|
61
|
+
| `worksheet.drawing?` | `Array<{ $: { "r:id": string } }>` | Drawing references |
|
|
82
62
|
|
|
83
|
-
|
|
63
|
+
### ExcelRowData
|
|
84
64
|
|
|
85
|
-
|
|
86
|
-
interface ExcelAddressRangePoint {
|
|
87
|
-
s: ExcelAddressPoint;
|
|
88
|
-
e: ExcelAddressPoint;
|
|
89
|
-
}
|
|
90
|
-
```
|
|
65
|
+
A single row in worksheet data.
|
|
91
66
|
|
|
92
|
-
|
|
67
|
+
| Field | Type | Description |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| `$.r` | `string` | Row address (1-based, e.g., "1") |
|
|
70
|
+
| `c?` | `ExcelCellData[]` | Cell data array |
|
|
93
71
|
|
|
94
|
-
###
|
|
72
|
+
### ExcelCellData
|
|
95
73
|
|
|
96
|
-
|
|
97
|
-
type ExcelBorderPosition = "left" | "right" | "top" | "bottom";
|
|
98
|
-
```
|
|
74
|
+
A single cell in row data.
|
|
99
75
|
|
|
100
|
-
|
|
76
|
+
| Field | Type | Description |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| `$.r` | `string` | Cell address (e.g., "A1") |
|
|
79
|
+
| `$.s?` | `string` | Style ID |
|
|
80
|
+
| `$.t?` | `ExcelCellType` | Cell type |
|
|
81
|
+
| `v?` | `[string]` | Cell value |
|
|
82
|
+
| `f?` | `[string]` | Cell formula |
|
|
83
|
+
| `is?` | `Array<{ t?: (string \| { _?: string })[] }>` | Inline string data |
|
|
101
84
|
|
|
102
|
-
|
|
103
|
-
type ExcelHorizontalAlign = "center" | "left" | "right";
|
|
104
|
-
```
|
|
85
|
+
### ExcelXmlDrawingData
|
|
105
86
|
|
|
106
|
-
|
|
87
|
+
Represents `xl/drawings/drawing*.xml`.
|
|
107
88
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
89
|
+
| Field | Type | Description |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| `wsDr.$` | `{ xmlns: string; "xmlns:a"?: string; "xmlns:r"?: string }` | XML namespaces |
|
|
92
|
+
| `wsDr.twoCellAnchor?` | Array | Two-cell anchor picture definitions (from/to coordinates, picture properties, blip fill) |
|
|
111
93
|
|
|
112
|
-
###
|
|
94
|
+
### ExcelXmlSharedStringData
|
|
113
95
|
|
|
114
|
-
|
|
96
|
+
Represents `xl/sharedStrings.xml`.
|
|
115
97
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
/** Horizontal alignment */
|
|
123
|
-
horizontalAlign?: ExcelHorizontalAlign;
|
|
124
|
-
/** Vertical alignment */
|
|
125
|
-
verticalAlign?: ExcelVerticalAlign;
|
|
126
|
-
/** Number format */
|
|
127
|
-
numberFormat?: ExcelNumberFormat;
|
|
128
|
-
}
|
|
129
|
-
```
|
|
98
|
+
| Field | Type | Description |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
| `sst.$` | `{ xmlns: string }` | XML namespace |
|
|
101
|
+
| `sst.si?` | `ExcelXmlSharedStringDataSi[]` | Shared string items |
|
|
102
|
+
|
|
103
|
+
### ExcelXmlSharedStringDataSi
|
|
130
104
|
|
|
131
|
-
**Example:**
|
|
132
105
|
```typescript
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
horizontalAlign: "center",
|
|
137
|
-
verticalAlign: "center",
|
|
138
|
-
numberFormat: "number",
|
|
139
|
-
});
|
|
106
|
+
type ExcelXmlSharedStringDataSi =
|
|
107
|
+
| { t: ExcelXmlSharedStringDataText }
|
|
108
|
+
| { r: { t: ExcelXmlSharedStringDataText }[] };
|
|
140
109
|
```
|
|
141
110
|
|
|
142
|
-
|
|
111
|
+
Either a plain text item (`t`) or a rich text item (`r`) with multiple runs.
|
|
143
112
|
|
|
144
|
-
###
|
|
113
|
+
### ExcelXmlSharedStringDataText
|
|
145
114
|
|
|
146
115
|
```typescript
|
|
147
|
-
|
|
148
|
-
readonly data: unknown;
|
|
149
|
-
cleanup(): void;
|
|
150
|
-
}
|
|
116
|
+
type ExcelXmlSharedStringDataText = [string | { $: { space?: "preserve" }; _?: string }];
|
|
151
117
|
```
|
|
152
118
|
|
|
153
|
-
|
|
119
|
+
A single-element tuple: either a plain string or an object with optional space-preservation attribute.
|
|
154
120
|
|
|
155
|
-
|
|
121
|
+
### ExcelXmlStyleData
|
|
156
122
|
|
|
157
|
-
|
|
123
|
+
Represents `xl/styles.xml`.
|
|
158
124
|
|
|
159
|
-
|
|
125
|
+
| Field | Type | Description |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| `styleSheet.$` | `{ xmlns: string }` | XML namespace |
|
|
128
|
+
| `styleSheet.numFmts?` | `[{ $: { count: string }; numFmt?: Array<{ $: { numFmtId: string; formatCode: string } }> }]` | Number format definitions |
|
|
129
|
+
| `styleSheet.fonts` | `[{ $: { count: string }; font: {}[] }]` | Font definitions |
|
|
130
|
+
| `styleSheet.fills` | `[{ $: { count: string }; fill: ExcelXmlStyleDataFill[] }]` | Fill definitions |
|
|
131
|
+
| `styleSheet.borders` | `[{ $: { count: string }; border: ExcelXmlStyleDataBorder[] }]` | Border definitions |
|
|
132
|
+
| `styleSheet.cellXfs` | `[{ $: { count: string }; xf: ExcelXmlStyleDataXf[] }]` | Cell format definitions |
|
|
160
133
|
|
|
161
|
-
|
|
162
|
-
interface ExcelXmlContentTypeData {
|
|
163
|
-
Types: {
|
|
164
|
-
$: { xmlns: string };
|
|
165
|
-
Default: { $: { Extension: string; ContentType: string } }[];
|
|
166
|
-
Override: { $: { PartName: string; ContentType: string } }[];
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
```
|
|
134
|
+
### ExcelXmlStyleDataXf
|
|
170
135
|
|
|
171
|
-
|
|
136
|
+
| Field | Type | Description |
|
|
137
|
+
|---|---|---|
|
|
138
|
+
| `$.numFmtId?` | `string` | Number format ID |
|
|
139
|
+
| `$.fontId?` | `string` | Font ID |
|
|
140
|
+
| `$.fillId?` | `string` | Fill ID |
|
|
141
|
+
| `$.borderId?` | `string` | Border ID |
|
|
142
|
+
| `$.xfId?` | `string` | Parent xf ID |
|
|
143
|
+
| `$.applyNumberFormat?` | `string` | Whether number format is applied |
|
|
144
|
+
| `$.applyFont?` | `string` | Whether font is applied |
|
|
145
|
+
| `$.applyAlignment?` | `string` | Whether alignment is applied |
|
|
146
|
+
| `$.applyFill?` | `string` | Whether fill is applied |
|
|
147
|
+
| `$.applyBorder?` | `string` | Whether border is applied |
|
|
148
|
+
| `alignment?` | `[{ $: { horizontal?: "center" \| "left" \| "right"; vertical?: "center" \| "top" \| "bottom" } }]` | Alignment settings |
|
|
172
149
|
|
|
173
|
-
|
|
150
|
+
### ExcelXmlStyleDataFill
|
|
174
151
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
$: { xmlns: string };
|
|
179
|
-
Relationship?: ExcelRelationshipData[];
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
```
|
|
152
|
+
| Field | Type | Description |
|
|
153
|
+
|---|---|---|
|
|
154
|
+
| `patternFill` | `[{ $: { patternType: "none" \| "solid" \| "gray125" }; fgColor?: [{ $: { rgb: string } }] }]` | Pattern fill with optional foreground color (ARGB) |
|
|
183
155
|
|
|
184
|
-
###
|
|
156
|
+
### ExcelXmlStyleDataBorder
|
|
185
157
|
|
|
186
|
-
|
|
158
|
+
| Field | Type | Description |
|
|
159
|
+
|---|---|---|
|
|
160
|
+
| `top?` | `[{ $: { style: "thin" \| "medium" }; color?: [{ $: { rgb: string } }] }]` | Top border |
|
|
161
|
+
| `left?` | `[{ $: { style: "thin" \| "medium" }; color?: [{ $: { rgb: string } }] }]` | Left border |
|
|
162
|
+
| `right?` | `[{ $: { style: "thin" \| "medium" }; color?: [{ $: { rgb: string } }] }]` | Right border |
|
|
163
|
+
| `bottom?` | `[{ $: { style: "thin" \| "medium" }; color?: [{ $: { rgb: string } }] }]` | Bottom border |
|
|
164
|
+
|
|
165
|
+
## Value Types
|
|
166
|
+
|
|
167
|
+
### ExcelValueType
|
|
187
168
|
|
|
188
169
|
```typescript
|
|
189
|
-
|
|
190
|
-
workbook: {
|
|
191
|
-
$: { "xmlns": string; "xmlns:r"?: string };
|
|
192
|
-
bookViews?: [{ workbookView: [{}] }];
|
|
193
|
-
sheets?: [{ sheet: { $: { "name": string; "sheetId": string; "r:id": string } }[] }];
|
|
194
|
-
};
|
|
195
|
-
}
|
|
170
|
+
type ExcelValueType = number | string | DateOnly | DateTime | Time | boolean | undefined;
|
|
196
171
|
```
|
|
197
172
|
|
|
198
|
-
|
|
173
|
+
Union of all supported cell value types. `DateOnly`, `DateTime`, and `Time` are from `@simplysm/core-common`.
|
|
199
174
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
### `ExcelRowData`
|
|
175
|
+
### ExcelNumberFormat
|
|
203
176
|
|
|
204
177
|
```typescript
|
|
205
|
-
|
|
206
|
-
$: { r: string }; // row address (1-based)
|
|
207
|
-
c?: ExcelCellData[];
|
|
208
|
-
}
|
|
178
|
+
type ExcelNumberFormat = "number" | "string" | "DateOnly" | "DateTime" | "Time";
|
|
209
179
|
```
|
|
210
180
|
|
|
211
|
-
|
|
181
|
+
Named number format categories for cell formatting.
|
|
182
|
+
|
|
183
|
+
### ExcelCellType
|
|
212
184
|
|
|
213
185
|
```typescript
|
|
214
|
-
|
|
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
|
-
}
|
|
186
|
+
type ExcelCellType = "s" | "b" | "str" | "n" | "inlineStr" | "e";
|
|
224
187
|
```
|
|
225
188
|
|
|
226
|
-
|
|
189
|
+
| Value | Description |
|
|
190
|
+
|---|---|
|
|
191
|
+
| `"s"` | Shared string |
|
|
192
|
+
| `"b"` | Boolean |
|
|
193
|
+
| `"str"` | Formula result string |
|
|
194
|
+
| `"n"` | Number |
|
|
195
|
+
| `"inlineStr"` | Inline string (rich text) |
|
|
196
|
+
| `"e"` | Error |
|
|
227
197
|
|
|
228
|
-
|
|
198
|
+
## Address Types
|
|
229
199
|
|
|
230
|
-
###
|
|
200
|
+
### ExcelAddressPoint
|
|
231
201
|
|
|
232
|
-
|
|
202
|
+
A cell coordinate (0-based).
|
|
233
203
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
si?: ExcelXmlSharedStringDataSi[];
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
```
|
|
204
|
+
| Field | Type | Description |
|
|
205
|
+
|---|---|---|
|
|
206
|
+
| `r` | `number` | Row index (0-based) |
|
|
207
|
+
| `c` | `number` | Column index (0-based) |
|
|
242
208
|
|
|
243
|
-
###
|
|
209
|
+
### ExcelAddressRangePoint
|
|
244
210
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
211
|
+
A rectangular cell range.
|
|
212
|
+
|
|
213
|
+
| Field | Type | Description |
|
|
214
|
+
|---|---|---|
|
|
215
|
+
| `s` | `ExcelAddressPoint` | Start (top-left) coordinate |
|
|
216
|
+
| `e` | `ExcelAddressPoint` | End (bottom-right) coordinate |
|
|
250
217
|
|
|
251
|
-
|
|
218
|
+
## ExcelXml Interface
|
|
252
219
|
|
|
253
220
|
```typescript
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
221
|
+
interface ExcelXml {
|
|
222
|
+
readonly data: unknown;
|
|
223
|
+
cleanup(): void;
|
|
224
|
+
}
|
|
257
225
|
```
|
|
258
226
|
|
|
259
|
-
|
|
227
|
+
Internal interface for XML document wrappers.
|
|
260
228
|
|
|
261
|
-
|
|
229
|
+
| Member | Type | Description |
|
|
230
|
+
|---|---|---|
|
|
231
|
+
| `data` | `readonly unknown` | Raw XML data |
|
|
232
|
+
| `cleanup()` | `void` | Release resources |
|
|
262
233
|
|
|
263
|
-
|
|
234
|
+
## Style Types
|
|
264
235
|
|
|
265
|
-
|
|
236
|
+
### ExcelBorderPosition
|
|
266
237
|
|
|
267
238
|
```typescript
|
|
268
|
-
|
|
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
|
-
}
|
|
239
|
+
type ExcelBorderPosition = "left" | "right" | "top" | "bottom";
|
|
283
240
|
```
|
|
284
241
|
|
|
285
|
-
###
|
|
242
|
+
### ExcelHorizontalAlign
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
type ExcelHorizontalAlign = "center" | "left" | "right";
|
|
246
|
+
```
|
|
286
247
|
|
|
287
|
-
|
|
248
|
+
### ExcelVerticalAlign
|
|
288
249
|
|
|
289
250
|
```typescript
|
|
290
|
-
|
|
291
|
-
patternFill: [{ $: { patternType: "none" | "solid" | "gray125" }; fgColor?: [{ $: { rgb: string } }] }];
|
|
292
|
-
}
|
|
251
|
+
type ExcelVerticalAlign = "center" | "top" | "bottom";
|
|
293
252
|
```
|
|
294
253
|
|
|
295
|
-
###
|
|
254
|
+
### ExcelStyleOptions
|
|
255
|
+
|
|
256
|
+
Cell style options.
|
|
296
257
|
|
|
297
|
-
|
|
258
|
+
| Field | Type | Description |
|
|
259
|
+
|---|---|---|
|
|
260
|
+
| `background?` | `string` | Background color in ARGB format (e.g., `"00FF0000"` for red) |
|
|
261
|
+
| `border?` | `ExcelBorderPosition[]` | Border positions to apply |
|
|
262
|
+
| `horizontalAlign?` | `ExcelHorizontalAlign` | Horizontal alignment |
|
|
263
|
+
| `verticalAlign?` | `ExcelVerticalAlign` | Vertical alignment |
|
|
264
|
+
| `numberFormat?` | `ExcelNumberFormat` | Number format |
|
|
265
|
+
|
|
266
|
+
## ExcelUtils
|
|
267
|
+
|
|
268
|
+
Static utility class for cell address conversion, date/number conversion, and number format handling.
|
|
269
|
+
|
|
270
|
+
### Static Methods
|
|
271
|
+
|
|
272
|
+
| Method | Signature | Description |
|
|
273
|
+
|---|---|---|
|
|
274
|
+
| `stringifyAddr` | `(point: ExcelAddressPoint) => string` | Convert cell coordinate to "A1" format string |
|
|
275
|
+
| `stringifyRowAddr` | `(r: number) => string` | Convert 0-based row index to row address (e.g., 0 -> "1") |
|
|
276
|
+
| `stringifyColAddr` | `(c: number) => string` | Convert 0-based column index to column address (e.g., 0 -> "A", 26 -> "AA") |
|
|
277
|
+
| `parseRowAddr` | `(addr: string) => number` | Extract 0-based row index from cell address (e.g., "A3" -> 2) |
|
|
278
|
+
| `parseColAddr` | `(addr: string) => number` | Extract 0-based column index from cell address (e.g., "B3" -> 1) |
|
|
279
|
+
| `parseCellAddr` | `(addr: string) => ExcelAddressPoint` | Parse cell address to coordinate (e.g., "B3" -> `{r: 2, c: 1}`) |
|
|
280
|
+
| `parseRangeAddr` | `(rangeAddr: string) => ExcelAddressRangePoint` | Parse range address (e.g., "A1:C3" -> `{s: {r:0,c:0}, e: {r:2,c:2}}`) |
|
|
281
|
+
| `stringifyRangeAddr` | `(point: ExcelAddressRangePoint) => string` | Convert range coordinate to address string |
|
|
282
|
+
| `convertTimeTickToNumber` | `(tick: number) => number` | Convert JS timestamp (ms) to Excel date number |
|
|
283
|
+
| `convertNumberToTimeTick` | `(value: number) => number` | Convert Excel date number to JS timestamp (ms) |
|
|
284
|
+
| `convertNumFmtCodeToName` | `(numFmtCode: string) => ExcelNumberFormat` | Convert number format code to format name |
|
|
285
|
+
| `convertNumFmtIdToName` | `(numFmtId: number) => ExcelNumberFormat` | Convert built-in number format ID to format name |
|
|
286
|
+
| `convertNumFmtNameToId` | `(numFmtName: ExcelNumberFormat) => number` | Convert format name to built-in format ID |
|
package/docs/wrapper.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# ExcelWrapper
|
|
2
2
|
|
|
3
|
-
Zod schema-based Excel wrapper
|
|
3
|
+
Zod schema-based typed Excel wrapper for type-safe reading and writing.
|
|
4
|
+
|
|
5
|
+
## ExcelWrapper\<TSchema\>
|
|
4
6
|
|
|
5
7
|
```typescript
|
|
6
|
-
|
|
8
|
+
class ExcelWrapper<TSchema extends z.ZodObject<z.ZodRawShape>>
|
|
7
9
|
```
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
Generic class parameterized by a Zod object schema. The schema defines the record structure and uses `.describe()` to set Excel header names.
|
|
10
12
|
|
|
11
13
|
### Constructor
|
|
12
14
|
|
|
@@ -14,61 +16,33 @@ import { ExcelWrapper } from "@simplysm/excel";
|
|
|
14
16
|
constructor(schema: TSchema)
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
| Parameter | Type | Description |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `schema` | `TSchema` (extends `z.ZodObject`) | Zod schema defining the record structure. Use `.describe("Header Name")` on each field to set the Excel column header. |
|
|
18
22
|
|
|
19
|
-
###
|
|
23
|
+
### Public Methods
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
| Method | Signature | Description |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| `read` | `(file: Bytes \| Blob, wsNameOrIndex?: string \| number, options?: { excludes?: (keyof z.infer<TSchema>)[] }) => Promise<z.infer<TSchema>[]>` | Read an Excel file into a typed record array. Validates each row against the Zod schema. Throws on validation failure or when no data is found. Default worksheet: index 0. |
|
|
28
|
+
| `write` | `(wsName: string, records: Partial<z.infer<TSchema>>[], options?: { excludes?: (keyof z.infer<TSchema>)[] }) => Promise<ExcelWorkbook>` | Convert records to an Excel workbook. Returns an `ExcelWorkbook` -- caller is responsible for resource management (`await using` or `close()`). Automatically: writes headers from schema descriptions, applies borders to all cells, highlights required field headers in yellow, sets 85% zoom, freezes the header row. |
|
|
22
29
|
|
|
23
|
-
|
|
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
|
+
### Read Behavior
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
32
|
+
- Maps Excel headers to schema fields using `.describe()` display names
|
|
33
|
+
- Skips rows where all values are null/empty
|
|
34
|
+
- Converts cell values to match schema types (string, number, boolean, DateOnly, DateTime, Time)
|
|
35
|
+
- Boolean fields default to `false` when empty
|
|
36
|
+
- Validates each row with `schema.safeParse()` and throws with detailed error messages on failure
|
|
35
37
|
|
|
36
|
-
|
|
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
|
|
38
|
+
### Write Behavior
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
- Header row uses schema field descriptions (falls back to field key)
|
|
41
|
+
- Required non-boolean fields get yellow background highlight (`00FFFF00`)
|
|
42
|
+
- All data cells get borders on all four sides
|
|
43
|
+
- Sets zoom to 85% and freezes the header row
|
|
43
44
|
|
|
44
|
-
###
|
|
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
|
|
45
|
+
### Usage Example
|
|
72
46
|
|
|
73
47
|
```typescript
|
|
74
48
|
import { z } from "zod";
|
|
@@ -77,24 +51,20 @@ import { ExcelWrapper } from "@simplysm/excel";
|
|
|
77
51
|
const schema = z.object({
|
|
78
52
|
name: z.string().describe("Name"),
|
|
79
53
|
age: z.number().describe("Age"),
|
|
80
|
-
|
|
81
|
-
|
|
54
|
+
active: z.boolean().describe("Active").default(false),
|
|
55
|
+
birthDate: z.instanceof(DateOnly).optional().describe("Birth Date"),
|
|
82
56
|
});
|
|
83
57
|
|
|
84
58
|
const wrapper = new ExcelWrapper(schema);
|
|
85
59
|
|
|
86
|
-
// Read
|
|
60
|
+
// Read
|
|
87
61
|
const records = await wrapper.read(fileBytes);
|
|
88
|
-
// records: { name: string; age: number;
|
|
62
|
+
// records: { name: string; age: number; active: boolean; birthDate?: DateOnly }[]
|
|
89
63
|
|
|
90
|
-
// Write
|
|
91
|
-
await using wb = await wrapper.write("
|
|
92
|
-
{ name: "Alice", age: 30,
|
|
64
|
+
// Write
|
|
65
|
+
await using wb = await wrapper.write("Sheet1", [
|
|
66
|
+
{ name: "Alice", age: 30, active: true },
|
|
93
67
|
{ name: "Bob", age: 25 },
|
|
94
68
|
]);
|
|
95
69
|
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
70
|
```
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/excel",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"author": "
|
|
3
|
+
"version": "14.0.4",
|
|
4
|
+
"description": "심플리즘 패키지 - 엑셀 (neutral)",
|
|
5
|
+
"author": "심플리즘",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -14,14 +14,16 @@
|
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
"docs",
|
|
18
17
|
"src",
|
|
19
|
-
"
|
|
18
|
+
"docs"
|
|
20
19
|
],
|
|
21
20
|
"sideEffects": false,
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^20.19.37"
|
|
23
|
+
},
|
|
22
24
|
"dependencies": {
|
|
23
25
|
"mime": "^4.1.0",
|
|
24
26
|
"zod": "^4.3.6",
|
|
25
|
-
"@simplysm/core-common": "
|
|
27
|
+
"@simplysm/core-common": "14.0.4"
|
|
26
28
|
}
|
|
27
29
|
}
|