当前位置:网站首页>Antd component upload uploads xlsx files and reads the contents of the files
Antd component upload uploads xlsx files and reads the contents of the files
2022-07-02 23:01:00 【Not bald】
xlsx package
This bag is a npm package , The version used here is :
“xlsx”: “^0.14.5”
Usage mode
First , Introduce... In the file :
import XLSX from 'xlsx';
And then in upload Component's beforeUpload Use in :
beforeUpload(files) {
const readFile = file => {
const [fileReader, data1] = [new FileReader(), {
}];
let [binaryData, workbook] = [null, null];
fileReader.onload = e => {
binaryData = e.target.result;
workbook = XLSX.read(binaryData, {
type: 'binary' });
Object.keys(workbook.Sheets).forEach(sheet => {
data1[sheet] = XLSX.utils
.sheet_to_json(workbook.Sheets[sheet], {
header: 1 })
.slice(1);
});
workbook.SheetNames.forEach(sheetName => {
const dataSheet = data1[sheetName];
for (let index = 0; index < dataSheet.length; index += 1) {
const row = dataSheet[index];
const item = {
name: row[0] ? row[0] : null,
snCode: row[1] ? row[1] : null,
macAddress: row[2] ? row[2] : null,
ipAddress: row[3] ? row[3] : null,
number: Number(row[4] ? row[4] : null),
podium: (row[5] ? row[5] : null) === ' yes ' ? true : false,
devices: [
{
ipAddress: row[6] ? row[6] : null,
location: 'top1'
},
{
ipAddress: row[7] ? row[7] : null,
location: 'side1'
},
{
ipAddress: row[8] ? row[8] : null,
location: 'front1'
},
{
ipAddress: row[9] ? row[9] : null,
location: 'front2'
},
]
};
fileData.push(item);
}
});
// fileData Table data
if (fileData.length > 0) {
that.setState({
tables: fileData,
});
message.success(' Successful import !');
}else {
message.error(' Import failed !')
}
};
fileReader.readAsBinaryString(file);
};
readFile(uploadFile);
边栏推荐
- [chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?
- 编辑卡顿
- [LeetCode] 数组中的第K个最大元素【215】
- 数据分析学习记录(二)---响应曲面法及Design-Expert的简单使用
- The motivation of AES Advanced Encryption Protocol
- Niuke network: maximum submatrix
- Motivation du Protocole de chiffrement avancé AES
- 解决Chrome浏览器和Edeg浏览器主页被篡改的方法
- 泛型与反射,看这篇就够了
- 【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
猜你喜欢

位的高阶运算

Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly

Local dealers play the community group purchase mode and share millions of operations

Qt QScrollArea

【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
![[LeetCode] 反转字符串中的单词 III【557】](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[LeetCode] 反转字符串中的单词 III【557】
![[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?](/img/b5/e746dd115995e82c93f667c58a601c.png)
[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?

杰理之、产线装配环节【篇】

从2022年Q1财报看携程的韧性和远景

E-commerce system microservice architecture
随机推荐
AES高級加密協議的動機闡述
归并排序详解及应用
1px pixel compatibility of mobile terminal, 1px border
容器化技术在嵌入式领域的应用
景联文科技低价策略帮助AI企业降低模型训练成本
Jatpack------LiveData
Lambda表达式:一篇文章带你通透
【硬件】标准阻值的由来
Golang interview finishing three resumes how to write
To myself who is about to work
[LeetCode] 反转字符串中的单词 III【557】
odoo13搭建医院HRP环境(详细步骤)
數據分析學習記錄--用EXCEL完成簡單的單因素方差分析
Wait to solve the zombie process
杰理之快速触摸不响应问题【篇】
mysql重置密码,忘记密码,重置root密码,重置mysql密码
Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]
世界环境日 | 周大福用心服务推动减碳环保
Splunk audit 的设定
杰理之直接触摸样机的顶针反应不正常【篇】