@simplysm/excel 14.0.22 → 14.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/excel",
3
- "version": "14.0.22",
3
+ "version": "14.0.24",
4
4
  "description": "심플리즘 패키지 - 엑셀 (neutral)",
5
5
  "author": "심플리즘",
6
6
  "license": "Apache-2.0",
@@ -14,8 +14,7 @@
14
14
  "types": "./dist/index.d.ts",
15
15
  "files": [
16
16
  "dist",
17
- "src",
18
- "docs"
17
+ "src"
19
18
  ],
20
19
  "sideEffects": false,
21
20
  "devDependencies": {
@@ -24,6 +23,6 @@
24
23
  "dependencies": {
25
24
  "mime": "^4.1.0",
26
25
  "zod": "^4.3.6",
27
- "@simplysm/core-common": "14.0.22"
26
+ "@simplysm/core-common": "14.0.24"
28
27
  }
29
28
  }
package/README.md DELETED
@@ -1,108 +0,0 @@
1
- # @simplysm/excel
2
-
3
- Excel file processing library -- read/write .xlsx files with cell styling, formulas, images, and Zod schema-based typed wrapper.
4
-
5
- Platform: neutral (Node.js and browser).
6
-
7
- ## Installation
8
-
9
- ```bash
10
- npm install @simplysm/excel
11
- ```
12
-
13
- ## API Overview
14
-
15
- | Category | Items | Documentation |
16
- |---|---|---|
17
- | Types | ExcelXmlContentTypeData, ExcelXmlRelationshipData, ExcelRelationshipData, ExcelXmlWorkbookData, ExcelXmlWorksheetData, ExcelRowData, ExcelCellData, ExcelXmlDrawingData, ExcelXmlSharedStringData, ExcelXmlSharedStringDataSi, ExcelXmlSharedStringDataText, ExcelXmlStyleData, ExcelXmlStyleDataXf, ExcelXmlStyleDataFill, ExcelXmlStyleDataBorder, ExcelValueType, ExcelNumberFormat, ExcelCellType, ExcelAddressPoint, ExcelAddressRangePoint, ExcelXml, ExcelBorderPosition, ExcelHorizontalAlign, ExcelVerticalAlign, ExcelStyleOptions | [docs/types.md](docs/types.md) |
18
- | Utils | ExcelUtils | [docs/utils.md](docs/utils.md) |
19
- | Core Classes | ExcelCell, ExcelRow, ExcelCol, ExcelWorksheet, ExcelWorkbook | [docs/core.md](docs/core.md) |
20
- | Wrapper | ExcelWrapper | [docs/wrapper.md](docs/wrapper.md) |
21
-
22
- ## Quick Start
23
-
24
- ### Read an existing Excel file
25
-
26
- ```typescript
27
- import { ExcelWorkbook } from "@simplysm/excel";
28
-
29
- await using wb = new ExcelWorkbook(fileBytes);
30
- const ws = await wb.getWorksheet(0);
31
-
32
- // Read a single cell
33
- const value = await ws.cell(0, 0).getValue();
34
-
35
- // Read as data table (first row = headers)
36
- const records = await ws.getDataTable();
37
- // records: Record<string, ExcelValueType>[]
38
- ```
39
-
40
- ### Create a new Excel file
41
-
42
- ```typescript
43
- import { ExcelWorkbook } from "@simplysm/excel";
44
-
45
- await using wb = new ExcelWorkbook();
46
- const ws = await wb.addWorksheet("Sheet1");
47
-
48
- await ws.cell(0, 0).setValue("Name");
49
- await ws.cell(0, 1).setValue("Age");
50
- await ws.cell(1, 0).setValue("Alice");
51
- await ws.cell(1, 1).setValue(30);
52
-
53
- // Apply styling
54
- await ws.cell(0, 0).setStyle({
55
- background: "00FFFF00",
56
- border: ["left", "right", "top", "bottom"],
57
- horizontalAlign: "center",
58
- });
59
-
60
- const bytes = await wb.toBytes();
61
- ```
62
-
63
- ### Typed read/write with Zod schema
64
-
65
- ```typescript
66
- import { z } from "zod";
67
- import { ExcelWrapper } from "@simplysm/excel";
68
-
69
- const schema = z.object({
70
- name: z.string().describe("Name"),
71
- age: z.number().describe("Age"),
72
- active: z.boolean().describe("Active").default(false),
73
- });
74
-
75
- const wrapper = new ExcelWrapper(schema);
76
-
77
- // Read with type safety and validation
78
- const records = await wrapper.read(fileBytes);
79
-
80
- // Write with automatic header/style generation
81
- await using wb = await wrapper.write("Sheet1", records);
82
- const bytes = await wb.toBytes();
83
- ```
84
-
85
- ### Insert an image
86
-
87
- ```typescript
88
- await ws.addImage({
89
- bytes: imageBytes,
90
- ext: "png",
91
- from: { r: 1, c: 1 },
92
- to: { r: 5, c: 3 },
93
- });
94
- ```
95
-
96
- ### Row operations
97
-
98
- ```typescript
99
- // Copy a row (overwrite)
100
- await ws.copyRow(0, 5);
101
-
102
- // Insert-copy a row (shifts existing rows down)
103
- await ws.insertCopyRow(0, 3);
104
-
105
- // Freeze header row and set zoom
106
- await ws.freezeAt({ r: 0 });
107
- await ws.setZoom(85);
108
- ```
package/docs/core.md DELETED
@@ -1,147 +0,0 @@
1
- # Core Classes
2
-
3
- Core classes for reading and writing Excel workbooks, worksheets, rows, columns, and cells.
4
-
5
- ## ExcelCell
6
-
7
- Represents a single Excel cell. Provides value read/write, formula, style, and cell merge operations.
8
-
9
- All methods are `async` because XML data (SharedStrings, Styles) is loaded on-demand for memory efficiency with large files.
10
-
11
- ### Properties
12
-
13
- | Property | Type | Description |
14
- |---|---|---|
15
- | `addr` | `readonly ExcelAddressPoint` | Cell address (0-based row/column index) |
16
-
17
- ### Public Methods
18
-
19
- | Method | Signature | Description |
20
- |---|---|---|
21
- | `setValue` | `(val: ExcelValueType) => Promise<void>` | Set cell value. Pass `undefined` to delete the cell. Handles string, number, boolean, DateOnly, DateTime, and Time types. Date/time values automatically apply the corresponding number format. |
22
- | `getValue` | `() => Promise<ExcelValueType>` | Read cell value. Returns the typed value based on cell type and number format. SharedString references are resolved automatically. |
23
- | `setFormula` | `(val: string \| undefined) => Promise<void>` | Set cell formula. Pass `undefined` to remove the formula. |
24
- | `getFormula` | `() => Promise<string \| undefined>` | Get cell formula. |
25
- | `merge` | `(r: number, c: number) => Promise<void>` | Merge from this cell to the given end coordinate (0-based). Example: `cell(0,0).merge(2,2)` merges A1:C3. |
26
- | `getStyleId` | `() => Promise<string \| undefined>` | Get the raw style ID of the cell. |
27
- | `setStyleId` | `(styleId: string \| undefined) => Promise<void>` | Set the raw style ID of the cell. |
28
- | `setStyle` | `(opts: ExcelStyleOptions) => Promise<void>` | Set cell style (background, border, alignment, number format). |
29
-
30
- ## ExcelRow
31
-
32
- Represents a row in an Excel worksheet. Provides cell access.
33
-
34
- ### Public Methods
35
-
36
- | Method | Signature | Description |
37
- |---|---|---|
38
- | `cell` | `(c: number) => ExcelCell` | Get cell at column index (0-based). Cached per instance. |
39
- | `getCells` | `() => Promise<ExcelCell[]>` | Get all cells in the row (within the worksheet's data range). |
40
-
41
- ## ExcelCol
42
-
43
- Represents a column in an Excel worksheet. Provides cell access and column width control.
44
-
45
- ### Public Methods
46
-
47
- | Method | Signature | Description |
48
- |---|---|---|
49
- | `cell` | `(r: number) => ExcelCell` | Get cell at row index (0-based). Cached per instance. |
50
- | `getCells` | `() => Promise<ExcelCell[]>` | Get all cells in the column (within the worksheet's data range). |
51
- | `setWidth` | `(size: number) => Promise<void>` | Set column width. |
52
-
53
- ## ExcelWorksheet
54
-
55
- Represents an Excel worksheet. Provides cell access, row/column copy, data table processing, image insertion, and view settings.
56
-
57
- ### Public Methods
58
-
59
- #### Name
60
-
61
- | Method | Signature | Description |
62
- |---|---|---|
63
- | `getName` | `() => Promise<string>` | Get worksheet name. |
64
- | `setName` | `(newName: string) => Promise<void>` | Rename the worksheet. |
65
-
66
- #### Cell Access
67
-
68
- | Method | Signature | Description |
69
- |---|---|---|
70
- | `row` | `(r: number) => ExcelRow` | Get row object (0-based). Cached per instance. |
71
- | `cell` | `(r: number, c: number) => ExcelCell` | Get cell object (0-based row/column). |
72
- | `col` | `(c: number) => ExcelCol` | Get column object (0-based). Cached per instance. |
73
-
74
- #### Copy
75
-
76
- | Method | Signature | Description |
77
- |---|---|---|
78
- | `copyRowStyle` | `(srcR: number, targetR: number) => Promise<void>` | Copy styles from source row to target row (all columns in range). |
79
- | `copyCellStyle` | `(srcAddr: ExcelAddressPoint, targetAddr: ExcelAddressPoint) => Promise<void>` | Copy style from source cell to target cell. |
80
- | `copyRow` | `(srcR: number, targetR: number) => Promise<void>` | Copy source row to target row (overwrite). |
81
- | `copyCell` | `(srcAddr: ExcelAddressPoint, targetAddr: ExcelAddressPoint) => Promise<void>` | Copy source cell to target cell. |
82
- | `insertCopyRow` | `(srcR: number, targetR: number) => Promise<void>` | Insert-copy source row at target position. Existing rows at and below target are shifted down by one. Merge cells spanning the insertion point are automatically extended. |
83
-
84
- #### Range & Data
85
-
86
- | Method | Signature | Description |
87
- |---|---|---|
88
- | `getRange` | `() => Promise<ExcelAddressRangePoint>` | Get the data range of the worksheet. |
89
- | `getCells` | `() => Promise<ExcelCell[][]>` | Get all cells as a 2D array. |
90
- | `getDataTable` | `(opt?: { headerRowIndex?: number; checkEndColIndex?: number; usableHeaderNameFn?: (headerName: string) => boolean }) => Promise<Record<string, ExcelValueType>[]>` | Read worksheet data as an array of records. First row (or `headerRowIndex`) is used as headers. `checkEndColIndex` stops reading when that column is empty. `usableHeaderNameFn` filters which headers to include. |
91
- | `setDataMatrix` | `(matrix: ExcelValueType[][]) => Promise<void>` | Write a 2D array to the worksheet (row-major, index 0 is first row). |
92
- | `setRecords` | `(records: Record<string, ExcelValueType>[]) => Promise<void>` | Write an array of records. Headers are auto-generated in the first row from record keys. |
93
-
94
- #### View
95
-
96
- | Method | Signature | Description |
97
- |---|---|---|
98
- | `setZoom` | `(percent: number) => Promise<void>` | Set zoom level (percent). |
99
- | `freezeAt` | `(point: { r?: number; c?: number }) => Promise<void>` | Freeze rows/columns at the given position. |
100
-
101
- #### Image
102
-
103
- | Method | Signature | Description |
104
- |---|---|---|
105
- | `addImage` | `(opts: { bytes: Bytes; ext: string; from: { r: number; c: number; rOff?: number \| string; cOff?: number \| string }; to?: { r: number; c: number; rOff?: number \| string; cOff?: number \| string } }) => Promise<void>` | Insert an image. `bytes` is the image binary data, `ext` is the file extension (e.g., "png"). `from`/`to` define the anchor coordinates (0-based). Offsets are in EMU. If `to` is omitted, the image spans one cell from `from`. |
106
-
107
- ## ExcelWorkbook
108
-
109
- Excel workbook processing class. Manages ZIP resources internally. Supports `await using` for automatic resource cleanup.
110
-
111
- ### Constructor
112
-
113
- ```typescript
114
- constructor(arg?: Blob | Bytes)
115
- ```
116
-
117
- - `arg`: Existing Excel file data (Blob or Uint8Array). Omit to create a new empty workbook.
118
-
119
- ### Properties
120
-
121
- | Property | Type | Description |
122
- |---|---|---|
123
- | `zipCache` | `readonly ZipCache` | Internal ZIP cache (advanced usage). |
124
-
125
- ### Public Methods
126
-
127
- #### Worksheet
128
-
129
- | Method | Signature | Description |
130
- |---|---|---|
131
- | `getWorksheetNames` | `() => Promise<string[]>` | Get all worksheet names. |
132
- | `addWorksheet` | `(name: string) => Promise<ExcelWorksheet>` | Create and return a new worksheet. |
133
- | `getWorksheet` | `(nameOrIndex: string \| number) => Promise<ExcelWorksheet>` | Get worksheet by name or 0-based index. Throws if not found. |
134
-
135
- #### Export
136
-
137
- | Method | Signature | Description |
138
- |---|---|---|
139
- | `toBytes` | `() => Promise<Bytes>` | Export workbook as byte array. |
140
- | `toBlob` | `() => Promise<Blob>` | Export workbook as Blob (MIME: `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`). |
141
-
142
- #### Lifecycle
143
-
144
- | Method | Signature | Description |
145
- |---|---|---|
146
- | `close` | `() => Promise<void>` | Release resources. Safe to call on already-closed workbooks (no-op). After calling, the instance cannot be used. |
147
- | `[Symbol.asyncDispose]` | `() => Promise<void>` | Async dispose support (`await using`). Calls `close()`. |
package/docs/types.md DELETED
@@ -1,265 +0,0 @@
1
- # Types
2
-
3
- Types and enums for Excel file processing.
4
-
5
- ## XML Data Types
6
-
7
- Internal XML structure types used by the library to represent .xlsx file contents.
8
-
9
- ### ExcelXmlContentTypeData
10
-
11
- Represents `[Content_Types].xml` in the .xlsx archive.
12
-
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 |
18
-
19
- ### ExcelXmlRelationshipData
20
-
21
- Represents a `_rels/*.rels` relationship file.
22
-
23
- | Field | Type | Description |
24
- |---|---|---|
25
- | `Relationships.$` | `{ xmlns: string }` | XML namespace |
26
- | `Relationships.Relationship?` | `ExcelRelationshipData[]` | Array of relationship entries |
27
-
28
- ### ExcelRelationshipData
29
-
30
- A single relationship entry.
31
-
32
- | Field | Type | Description |
33
- |---|---|---|
34
- | `$.Id` | `string` | Relationship ID (e.g., "rId1") |
35
- | `$.Target` | `string` | Target path |
36
- | `$.Type` | `string` | Relationship type URI |
37
-
38
- ### ExcelXmlWorkbookData
39
-
40
- Represents `xl/workbook.xml`.
41
-
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 |
47
-
48
- ### ExcelXmlWorksheetData
49
-
50
- Represents `xl/worksheets/sheet*.xml`.
51
-
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 |
62
-
63
- ### ExcelRowData
64
-
65
- A single row in worksheet data.
66
-
67
- | Field | Type | Description |
68
- |---|---|---|
69
- | `$.r` | `string` | Row address (1-based, e.g., "1") |
70
- | `c?` | `ExcelCellData[]` | Cell data array |
71
-
72
- ### ExcelCellData
73
-
74
- A single cell in row data.
75
-
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 |
84
-
85
- ### ExcelXmlDrawingData
86
-
87
- Represents `xl/drawings/drawing*.xml`.
88
-
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) |
93
-
94
- ### ExcelXmlSharedStringData
95
-
96
- Represents `xl/sharedStrings.xml`.
97
-
98
- | Field | Type | Description |
99
- |---|---|---|
100
- | `sst.$` | `{ xmlns: string }` | XML namespace |
101
- | `sst.si?` | `ExcelXmlSharedStringDataSi[]` | Shared string items |
102
-
103
- ### ExcelXmlSharedStringDataSi
104
-
105
- ```typescript
106
- type ExcelXmlSharedStringDataSi =
107
- | { t: ExcelXmlSharedStringDataText }
108
- | { r: { t: ExcelXmlSharedStringDataText }[] };
109
- ```
110
-
111
- Either a plain text item (`t`) or a rich text item (`r`) with multiple runs.
112
-
113
- ### ExcelXmlSharedStringDataText
114
-
115
- ```typescript
116
- type ExcelXmlSharedStringDataText = [string | { $: { space?: "preserve" }; _?: string }];
117
- ```
118
-
119
- A single-element tuple: either a plain string or an object with optional space-preservation attribute.
120
-
121
- ### ExcelXmlStyleData
122
-
123
- Represents `xl/styles.xml`.
124
-
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 |
133
-
134
- ### ExcelXmlStyleDataXf
135
-
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 |
149
-
150
- ### ExcelXmlStyleDataFill
151
-
152
- | Field | Type | Description |
153
- |---|---|---|
154
- | `patternFill` | `[{ $: { patternType: "none" \| "solid" \| "gray125" }; fgColor?: [{ $: { rgb: string } }] }]` | Pattern fill with optional foreground color (ARGB) |
155
-
156
- ### ExcelXmlStyleDataBorder
157
-
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
168
-
169
- ```typescript
170
- type ExcelValueType = number | string | DateOnly | DateTime | Time | boolean | undefined;
171
- ```
172
-
173
- Union of all supported cell value types. `DateOnly`, `DateTime`, and `Time` are from `@simplysm/core-common`.
174
-
175
- ### ExcelNumberFormat
176
-
177
- ```typescript
178
- type ExcelNumberFormat = "number" | "string" | "DateOnly" | "DateTime" | "Time";
179
- ```
180
-
181
- Named number format categories for cell formatting.
182
-
183
- ### ExcelCellType
184
-
185
- ```typescript
186
- type ExcelCellType = "s" | "b" | "str" | "n" | "inlineStr" | "e";
187
- ```
188
-
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 |
197
-
198
- ## Address Types
199
-
200
- ### ExcelAddressPoint
201
-
202
- A cell coordinate (0-based).
203
-
204
- | Field | Type | Description |
205
- |---|---|---|
206
- | `r` | `number` | Row index (0-based) |
207
- | `c` | `number` | Column index (0-based) |
208
-
209
- ### ExcelAddressRangePoint
210
-
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 |
217
-
218
- ## ExcelXml Interface
219
-
220
- ```typescript
221
- interface ExcelXml {
222
- readonly data: unknown;
223
- cleanup(): void;
224
- }
225
- ```
226
-
227
- Internal interface for XML document wrappers.
228
-
229
- | Member | Type | Description |
230
- |---|---|---|
231
- | `data` | `readonly unknown` | Raw XML data |
232
- | `cleanup()` | `void` | Release resources |
233
-
234
- ## Style Types
235
-
236
- ### ExcelBorderPosition
237
-
238
- ```typescript
239
- type ExcelBorderPosition = "left" | "right" | "top" | "bottom";
240
- ```
241
-
242
- ### ExcelHorizontalAlign
243
-
244
- ```typescript
245
- type ExcelHorizontalAlign = "center" | "left" | "right";
246
- ```
247
-
248
- ### ExcelVerticalAlign
249
-
250
- ```typescript
251
- type ExcelVerticalAlign = "center" | "top" | "bottom";
252
- ```
253
-
254
- ### ExcelStyleOptions
255
-
256
- Cell style options.
257
-
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
-
package/docs/utils.md DELETED
@@ -1,41 +0,0 @@
1
- # Utils
2
-
3
- ## `ExcelUtils`
4
-
5
- Static utility class for Excel address conversion, date/number conversion, and number format handling.
6
-
7
- ```typescript
8
- export class ExcelUtils {
9
- static stringifyAddr(point: ExcelAddressPoint): string;
10
- static stringifyRowAddr(r: number): string;
11
- static stringifyColAddr(c: number): string;
12
- static parseRowAddr(addr: string): number;
13
- static parseColAddr(addr: string): number;
14
- static parseCellAddr(addr: string): ExcelAddressPoint;
15
- static parseRangeAddr(rangeAddr: string): ExcelAddressRangePoint;
16
- static stringifyRangeAddr(point: ExcelAddressRangePoint): string;
17
- static convertTimeTickToNumber(tick: number): number;
18
- static convertNumberToTimeTick(value: number): number;
19
- static convertNumFmtCodeToName(numFmtCode: string): ExcelNumberFormat;
20
- static convertNumFmtIdToName(numFmtId: number): ExcelNumberFormat;
21
- static convertNumFmtNameToId(numFmtName: ExcelNumberFormat): number;
22
- }
23
- ```
24
-
25
- ### Methods
26
-
27
- | Method | Parameters | Returns | Description |
28
- |---|---|---|---|
29
- | `stringifyAddr` | `point: ExcelAddressPoint` | `string` | Convert coordinate to "A1" format string |
30
- | `stringifyRowAddr` | `r: number` | `string` | Convert row index (0-based) to row address (e.g. 0 -> "1") |
31
- | `stringifyColAddr` | `c: number` | `string` | Convert column index (0-based) to column address (e.g. 0 -> "A", 26 -> "AA"). Range: 0-16383 |
32
- | `parseRowAddr` | `addr: string` | `number` | Extract row index from cell address (e.g. "A3" -> 2) |
33
- | `parseColAddr` | `addr: string` | `number` | Extract column index from cell address (e.g. "B3" -> 1) |
34
- | `parseCellAddr` | `addr: string` | `ExcelAddressPoint` | Parse cell address to coordinate (e.g. "B3" -> `{r: 2, c: 1}`) |
35
- | `parseRangeAddr` | `rangeAddr: string` | `ExcelAddressRangePoint` | Parse range address to coordinates (e.g. "A1:C3" -> `{s: {r:0,c:0}, e: {r:2,c:2}}`) |
36
- | `stringifyRangeAddr` | `point: ExcelAddressRangePoint` | `string` | Convert range coordinates to address string |
37
- | `convertTimeTickToNumber` | `tick: number` | `number` | Convert JS timestamp (ms) to Excel date number (1900 date system) |
38
- | `convertNumberToTimeTick` | `value: number` | `number` | Convert Excel date number to JS timestamp (ms) |
39
- | `convertNumFmtCodeToName` | `numFmtCode: string` | `ExcelNumberFormat` | Convert number format code string to format name |
40
- | `convertNumFmtIdToName` | `numFmtId: number` | `ExcelNumberFormat` | Convert built-in number format ID to format name |
41
- | `convertNumFmtNameToId` | `numFmtName: ExcelNumberFormat` | `number` | Convert format name to built-in number format ID |
package/docs/wrapper.md DELETED
@@ -1,70 +0,0 @@
1
- # ExcelWrapper
2
-
3
- Zod schema-based typed Excel wrapper for type-safe reading and writing.
4
-
5
- ## ExcelWrapper\<TSchema\>
6
-
7
- ```typescript
8
- class ExcelWrapper<TSchema extends z.ZodObject<z.ZodRawShape>>
9
- ```
10
-
11
- Generic class parameterized by a Zod object schema. The schema defines the record structure and uses `.describe()` to set Excel header names.
12
-
13
- ### Constructor
14
-
15
- ```typescript
16
- constructor(schema: TSchema)
17
- ```
18
-
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. |
22
-
23
- ### Public Methods
24
-
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. |
29
-
30
- ### Read Behavior
31
-
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
37
-
38
- ### Write Behavior
39
-
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
44
-
45
- ### Usage Example
46
-
47
- ```typescript
48
- import { z } from "zod";
49
- import { ExcelWrapper } from "@simplysm/excel";
50
-
51
- const schema = z.object({
52
- name: z.string().describe("Name"),
53
- age: z.number().describe("Age"),
54
- active: z.boolean().describe("Active").default(false),
55
- birthDate: z.instanceof(DateOnly).optional().describe("Birth Date"),
56
- });
57
-
58
- const wrapper = new ExcelWrapper(schema);
59
-
60
- // Read
61
- const records = await wrapper.read(fileBytes);
62
- // records: { name: string; age: number; active: boolean; birthDate?: DateOnly }[]
63
-
64
- // Write
65
- await using wb = await wrapper.write("Sheet1", [
66
- { name: "Alice", age: 30, active: true },
67
- { name: "Bob", age: 25 },
68
- ]);
69
- const bytes = await wb.toBytes();
70
- ```