@senlinz/import-export 0.1.0 → 0.1.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/README.md CHANGED
@@ -15,7 +15,7 @@ pnpm add @senlinz/import-export
15
15
  ### Default mode (recommended)
16
16
 
17
17
  - No setup required.
18
- - `importExcel`, `exportExcel`, `fromExcel`, `toExcel`, `downloadExcelTemplate`, and `generateExcelTemplate` automatically initialize the bundled WASM runtime.
18
+ - `importExcel`, `importExcelDynamic`, `exportExcel`, `fromExcel`, `fromExcelDynamic`, `toExcel`, `downloadExcelTemplate`, and `generateExcelTemplate` automatically initialize the bundled WASM runtime.
19
19
  - Best for most browser applications.
20
20
 
21
21
  ### Advanced mode
@@ -58,6 +58,42 @@ If you provide invalid manual input, `initializeWasm(...)` throws a clear error
58
58
  - `progressCallback` - progress hook for long-running import/export work
59
59
  - `imageFetcher` - required resolver for `image` columns during export
60
60
 
61
+ ### Schema-less import
62
+
63
+ Use `importExcelDynamic(options?)` when you want to open the browser file picker without defining `columns` ahead of time.
64
+
65
+ ```ts
66
+ import { importExcelDynamic } from '@senlinz/import-export';
67
+
68
+ const result = await importExcelDynamic({
69
+ sheetName: 'sheet1',
70
+ headerRow: 1,
71
+ });
72
+
73
+ console.log(result.headers);
74
+ console.log(result.rows);
75
+ ```
76
+
77
+ Use `fromExcelDynamic(buffer, options?)` when you want to read caller-provided workbook bytes without defining `columns` ahead of time.
78
+
79
+ ```ts
80
+ import { fromExcelDynamic } from '@senlinz/import-export';
81
+
82
+ const result = await fromExcelDynamic(fileBytes, {
83
+ sheetName: 'sheet1',
84
+ headerRow: 1,
85
+ });
86
+
87
+ console.log(result.headers);
88
+ console.log(result.rows);
89
+ ```
90
+
91
+ - `importExcelDynamic(...)` depends on DOM/browser file upload APIs.
92
+ - `sheetName` is optional and falls back to the first worksheet when missing.
93
+ - `headerRow` is optional, 1-based, and defaults to the first non-empty row in the selected sheet.
94
+ - The result shape is `{ sheetName, headers, rows }`.
95
+ - Dynamic import requires non-empty, unique header names in the selected header row.
96
+
61
97
  ### Stable column fields
62
98
 
63
99
  - `key` - unique programmatic field key
@@ -114,6 +150,7 @@ const rows = await importExcel(definition);
114
150
  - Empty imported `number` and `date` cells are returned as `null`.
115
151
  - Imported `date` values are returned as formatted strings.
116
152
  - Unknown or malformed schemas fail fast before any workbook operation starts.
153
+ - Use `importExcelDynamic(...)` for browser uploads without a schema, or `fromExcelDynamic(...)` when you already have workbook bytes.
117
154
 
118
155
  ## Export behavior
119
156
 
@@ -138,8 +175,9 @@ These advanced features are supported and considered part of the public API:
138
175
  ## Browser/runtime support
139
176
 
140
177
  - Browser ESM runtimes are the primary target.
141
- - `downloadExcelTemplate`, `exportExcel`, and `importExcel` require DOM/browser APIs.
178
+ - `downloadExcelTemplate`, `exportExcel`, `importExcel`, and `importExcelDynamic` require DOM/browser APIs.
142
179
  - `fromExcel`, `toExcel`, and `generateExcelTemplate` can be used in other runtimes when browser-compatible globals are available.
180
+ - `fromExcelDynamic` can also be used in other runtimes when browser-compatible globals are available.
143
181
  - `initializeWasm` can be used to pre-initialize the runtime with caller-managed `source`, `bytes`, or `module`.
144
182
 
145
183
  ## Examples
package/README.zh.md CHANGED
@@ -15,7 +15,7 @@ pnpm add @senlinz/import-export
15
15
  ### 默认模式(推荐)
16
16
 
17
17
  - 无需额外初始化。
18
- - `importExcel`、`exportExcel`、`fromExcel`、`toExcel`、`downloadExcelTemplate`、`generateExcelTemplate` 会自动初始化内置 WASM 运行时。
18
+ - `importExcel`、`importExcelDynamic`、`exportExcel`、`fromExcel`、`fromExcelDynamic`、`toExcel`、`downloadExcelTemplate`、`generateExcelTemplate` 会自动初始化内置 WASM 运行时。
19
19
  - 适合绝大多数浏览器场景。
20
20
 
21
21
  ### 高级模式
@@ -107,6 +107,35 @@ await exportExcel(definition, [
107
107
  const rows = await importExcel(definition);
108
108
  ```
109
109
 
110
+ ## 动态导入
111
+
112
+ 当你不想预先定义 `columns`,并希望直接使用浏览器文件选择框时,可使用 `importExcelDynamic(options?)`。
113
+
114
+ ```ts
115
+ import { importExcelDynamic } from '@senlinz/import-export';
116
+
117
+ const result = await importExcelDynamic({
118
+ sheetName: 'sheet1',
119
+ headerRow: 1,
120
+ });
121
+ ```
122
+
123
+ 当你已经拿到工作簿字节数据时,可继续使用 `fromExcelDynamic(buffer, options?)`。
124
+
125
+ ```ts
126
+ import { fromExcelDynamic } from '@senlinz/import-export';
127
+
128
+ const result = await fromExcelDynamic(fileBytes, {
129
+ sheetName: 'sheet1',
130
+ headerRow: 1,
131
+ });
132
+ ```
133
+
134
+ - `importExcelDynamic(...)` 依赖 DOM / 浏览器文件上传 API。
135
+ - `sheetName` 可选,未提供或不存在时会回退到第一个工作表。
136
+ - `headerRow` 可选,使用从 `1` 开始的行号,默认会自动选择首个非空行。
137
+ - 返回值结构为 `{ sheetName, headers, rows }`。
138
+
110
139
  ## 导入行为
111
140
 
112
141
  - 表头必须与 `columns[].name` 完全一致。
@@ -114,6 +143,7 @@ const rows = await importExcel(definition);
114
143
  - 空的 `number` / `date` 单元格导入后返回 `null`。
115
144
  - `date` 列导入后返回格式化字符串。
116
145
  - 非法或不完整的 schema 会在读取工作簿前立即失败。
146
+ - 无 schema 导入时,可使用 `importExcelDynamic(...)`(浏览器上传)或 `fromExcelDynamic(...)`(字节缓冲)。
117
147
 
118
148
  ## 导出行为
119
149
 
@@ -138,8 +168,8 @@ const rows = await importExcel(definition);
138
168
  ## 浏览器 / 运行时支持
139
169
 
140
170
  - 主要面向浏览器 ESM 运行时。
141
- - `downloadExcelTemplate`、`exportExcel`、`importExcel` 依赖 DOM / 浏览器 API。
142
- - 当运行时提供兼容的浏览器全局对象时,也可以使用 `fromExcel`、`toExcel`、`generateExcelTemplate`。
171
+ - `downloadExcelTemplate`、`exportExcel`、`importExcel`、`importExcelDynamic` 依赖 DOM / 浏览器 API。
172
+ - 当运行时提供兼容的浏览器全局对象时,也可以使用 `fromExcel`、`fromExcelDynamic`、`toExcel`、`generateExcelTemplate`。
143
173
  - `initializeWasm` 可用于使用调用方提供的 `source`、`bytes` 或 `module` 预初始化运行时。
144
174
 
145
175
  ## 示例