当前位置:网站首页>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);
边栏推荐
- MySQL reset password, forget password, reset root password, reset MySQL password
- 【喜欢的诗词】好了歌
- 大一学习分享
- uniapp微信登录返显用户名和头像
- 创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
- stop slave卡住--事务的事件没有复制完整
- Array advanced improvement
- Il n'est pas nécessaire d'appuyer longtemps sur la fonction de démarrage pour modifier Jelly [chapitre]
- Chow-Liu Tree
- To myself who is about to work
猜你喜欢
Jatpack------LiveData
[leetcode] most elements [169]
LeetCode 968. 监控二叉树
Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
Niuke network: maximum submatrix
数据标注典型案例,景联文科技如何助力企业搭建数据方案
Wait to solve the zombie process
加油站[问题分析->问题转换->贪心]
Generics and reflection, this is enough
[羊城杯2020]easyphp
随机推荐
easyclick,ec权朗网络验证源码
【硬件】标准阻值的由来
【洛谷P1541】乌龟棋【DP】
Learning records of data analysis (II) -- simple use of response surface method and design expert
antd组件upload上传xlsx文件,并读取文件内容
Go 4 modes Singleton
Storage unit conversion
Jerry's built-in short press and long press, no matter how long it is, it is a short press [chapter]
加油站[问题分析->问题转换->贪心]
损失函数~
数据分析学习记录--用EXCEL完成简单的单因素方差分析
1px pixel compatibility of mobile terminal, 1px border
分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少
AES高級加密協議的動機闡述
boot actuator - prometheus使用
[leetcode] reverse string [344]
LeetCode 968. Monitor binary tree
Zhong Xuegao responded that the product will not melt for 1 hour: it contains solid components and cannot melt into water
Go condition variable
QT qsplitter splitter