fix xlsx
This commit is contained in:
parent
ad94d3afac
commit
eb0aa4ed63
|
|
@ -1,7 +1,7 @@
|
||||||
import { GFCol } from "@/gen/utils";
|
import { GFCol } from "@/gen/utils";
|
||||||
import { useLocal } from "@/utils/use-local";
|
import { useLocal } from "@/utils/use-local";
|
||||||
import { ChangeEvent, FC, MouseEvent } from "react";
|
import { ChangeEvent, FC, MouseEvent } from "react";
|
||||||
import * as XLSX from "xlsx";
|
// import * as XLSX from "xlsx";
|
||||||
|
|
||||||
type ImportExcelProps = {
|
type ImportExcelProps = {
|
||||||
gen_fields: string[];
|
gen_fields: string[];
|
||||||
|
|
@ -50,18 +50,18 @@ export const ImportExcel: FC<ImportExcelProps> = ({
|
||||||
reader.onload = (event: ProgressEvent<FileReader>) => {
|
reader.onload = (event: ProgressEvent<FileReader>) => {
|
||||||
if (!event.target?.result) return;
|
if (!event.target?.result) return;
|
||||||
|
|
||||||
const workbook = XLSX.read(event.target.result, { type: "binary" });
|
// const workbook = XLSX.read(event.target.result, { type: "binary" });
|
||||||
const sheetName = workbook.SheetNames[0];
|
// const sheetName = workbook.SheetNames[0];
|
||||||
const sheet = workbook.Sheets[sheetName];
|
// const sheet = workbook.Sheets[sheetName];
|
||||||
const sheetData = XLSX.utils.sheet_to_json(sheet);
|
// const sheetData = XLSX.utils.sheet_to_json(sheet);
|
||||||
local.data = sheetData;
|
// local.data = sheetData;
|
||||||
local.columns = getAllKeys(local.data);
|
// local.columns = getAllKeys(local.data);
|
||||||
gen_fields.forEach((data: any) => {
|
// gen_fields.forEach((data: any) => {
|
||||||
local.fields.push(JSON.parse(data).name);
|
// local.fields.push(JSON.parse(data).name);
|
||||||
});
|
// });
|
||||||
local.tableName = gen_table;
|
// local.tableName = gen_table;
|
||||||
local.showPreviewExcel = true;
|
// local.showPreviewExcel = true;
|
||||||
local.render();
|
// local.render();
|
||||||
};
|
};
|
||||||
reader.readAsBinaryString(file);
|
reader.readAsBinaryString(file);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue