@ticatec/batch-data-uploader 0.1.2 → 0.1.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/dist/BaseTemplate.d.ts +8 -0
- package/dist/BaseTemplate.js +29 -1
- package/package.json +1 -1
package/dist/BaseTemplate.d.ts
CHANGED
|
@@ -22,6 +22,14 @@ export default abstract class BaseTemplate {
|
|
|
22
22
|
* @param sheetName 如果不传则使用第一个工作表
|
|
23
23
|
*/
|
|
24
24
|
parseSheet(sheetName?: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* 方便函数:根据行号和列号(从0开始)获取单元格的值
|
|
27
|
+
* @param r 行索引 (0 表示第1行)
|
|
28
|
+
* @param c 列索引 (0 表示第A列)
|
|
29
|
+
*/
|
|
30
|
+
protected getCellValue(r: number, c: number): any;
|
|
31
|
+
protected extractFormAttributes(): void;
|
|
32
|
+
protected appendMoreFields(rowData: any, data: any): void;
|
|
25
33
|
protected extractData(arr: Array<any>): any[];
|
|
26
34
|
protected wrapData(data: any): any;
|
|
27
35
|
get columns(): Array<TableColumn>;
|
package/dist/BaseTemplate.js
CHANGED
|
@@ -25,7 +25,7 @@ export default class BaseTemplate {
|
|
|
25
25
|
this._list = [];
|
|
26
26
|
try {
|
|
27
27
|
const buffer = await file.arrayBuffer();
|
|
28
|
-
this._workbook = XLSX.read(buffer, { type: 'array' });
|
|
28
|
+
this._workbook = XLSX.read(buffer, { type: 'array', cellNF: true });
|
|
29
29
|
if (!this._workbook.SheetNames || this._workbook.SheetNames.length === 0) {
|
|
30
30
|
throw new Error('Excel file contains no worksheets');
|
|
31
31
|
}
|
|
@@ -61,6 +61,7 @@ export default class BaseTemplate {
|
|
|
61
61
|
if (range.e.r < rowOffset) {
|
|
62
62
|
throw new Error(`Not enough rows in sheet "${targetSheetName}". Expected at least ${rowOffset + 1} rows`);
|
|
63
63
|
}
|
|
64
|
+
this.extractFormAttributes();
|
|
64
65
|
const rows = [];
|
|
65
66
|
for (let rowIndex = range.s.r + rowOffset; rowIndex <= range.e.r; rowIndex++) {
|
|
66
67
|
const rowObject = {};
|
|
@@ -112,6 +113,32 @@ export default class BaseTemplate {
|
|
|
112
113
|
throw new Error(`Failed to parse sheet "${targetSheetName}": ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
113
114
|
}
|
|
114
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* 方便函数:根据行号和列号(从0开始)获取单元格的值
|
|
118
|
+
* @param r 行索引 (0 表示第1行)
|
|
119
|
+
* @param c 列索引 (0 表示第A列)
|
|
120
|
+
*/
|
|
121
|
+
getCellValue(r, c) {
|
|
122
|
+
if (!this._workbook || !this._currentSheetName) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const sheet = this._workbook.Sheets[this._currentSheetName];
|
|
126
|
+
if (!sheet)
|
|
127
|
+
return null;
|
|
128
|
+
const cellAddress = { r, c };
|
|
129
|
+
const cellRef = XLSX.utils.encode_cell(cellAddress);
|
|
130
|
+
const cell = sheet[cellRef];
|
|
131
|
+
if (!cell || cell.v === undefined)
|
|
132
|
+
return null;
|
|
133
|
+
if (cell.t === 'n' && cell.z && /y|m|d|h|s/i.test(cell.z)) {
|
|
134
|
+
return new Date(Math.round((cell.v - 25569) * 86400 * 1000));
|
|
135
|
+
}
|
|
136
|
+
return cell.v;
|
|
137
|
+
}
|
|
138
|
+
extractFormAttributes() {
|
|
139
|
+
}
|
|
140
|
+
appendMoreFields(rowData, data) {
|
|
141
|
+
}
|
|
115
142
|
extractData(arr) {
|
|
116
143
|
return arr.map(item => {
|
|
117
144
|
let result = {};
|
|
@@ -121,6 +148,7 @@ export default class BaseTemplate {
|
|
|
121
148
|
utils.setNestedValue(result, col.field, utils.getNestedValue(data, col.field));
|
|
122
149
|
}
|
|
123
150
|
}
|
|
151
|
+
this.appendMoreFields(item.data, result);
|
|
124
152
|
return result;
|
|
125
153
|
});
|
|
126
154
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ticatec/batch-data-uploader",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "A reusable Svelte component for batch uploading Excel data with support for error handling, multi-language, and preprocessing.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite dev",
|