<script src="https://cdn.bootcdn.net/ajax/libs/xlsx/0.17.4/xlsx.full.min.js"></script>
yarn add @types/file-saver
yarn add file-saver
<Button>
<label htmlFor="inputName">批量導(dǎo)入excel</label>
<input
style={{ opacity: 0, position: "absolute", cursor: "pointer" }}
id="inputName"
type="file"
accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
onChange={(e) => {
console.log("e", e, e.target.value, e.target.files);
let wb;
const obj = e.target;
//開始導(dǎo)入
if (!obj.files) {
return;
}
let f = obj.files[0];
let reader = new FileReader();
reader.onload = function (e: any) {
console.log("onload", e);
let data = e.target.result;
wb = window.XLSX.read(data, {
type: "binary",
});
let excelJson = window.XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
console.log(JSON.stringify(excelJson));
const list: any[] = excelJson.map((v, i) => {
// console.log(i, v);
});
console.log("list");
};
reader.readAsBinaryString(f);
}}
/>
</Button>
<Button
onClick={() => {
window.open("/Saleman.xls");
}}
>
下載模板e(cuò)xcel
</Button>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者