feat: 新增通用导入中心

This commit is contained in:
2026-08-05 17:11:39 +08:00
parent e9c8a1085d
commit 0c94ca54df
20 changed files with 3355 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import * as ExcelJS from 'exceljs';
import { cellValue, textValue } from './imports.helpers';
import type { CellValue } from './imports.types';
const MAX_SHEETS = 30;
const MAX_ROWS_PER_SHEET = 3000;
const MAX_COLS_PER_SHEET = 60;
export interface ImportSheetData {
name: string;
headers: string[];
rows: CellValue[][];
}
export function extractSheets(workbook: ExcelJS.Workbook): ImportSheetData[] {
const sheets: ImportSheetData[] = [];
for (const worksheet of workbook.worksheets) {
if (sheets.length >= MAX_SHEETS) break;
const headers: string[] = [];
const rows: CellValue[][] = [];
const firstRow = worksheet.getRow(1);
for (let col = 1; col <= Math.min(firstRow.cellCount, MAX_COLS_PER_SHEET); col += 1) {
const header = textValue(cellValue(firstRow.getCell(col)));
headers.push(header);
}
if (!headers.some(Boolean)) continue;
worksheet.eachRow({ includeEmpty: false }, (row, rowNumber) => {
if (rowNumber === 1 || rows.length >= MAX_ROWS_PER_SHEET) return;
const values: CellValue[] = [];
for (let col = 1; col <= headers.length; col += 1) {
values.push(cellValue(row.getCell(col)));
}
if (values.every((v) => v === null || textValue(v) === '')) return;
rows.push(values);
});
if (rows.length > 0) sheets.push({ name: worksheet.name, headers, rows });
}
return sheets;
}