当前位置:网站首页>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);
边栏推荐
- Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月1日08:43:06
- antd组件upload上传xlsx文件,并读取文件内容
- Stop slave is stuck -- the event of the transaction is not copied completely
- Wait to solve the zombie process
- To myself who is about to work
- PMP项目整合管理
- PMP project integration management
- 杰理之充电拔出,无法触摸开机【篇】
- Golang的学习路线
- [Solved] Splunk: Cannot get username when all users are selected“
猜你喜欢
创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
【硬件】标准阻值的由来
加油站[问题分析->问题转换->贪心]
Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
海思3559万能平台搭建:在截获的YUV图像上旋转操作
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
Mask R-CNN
The kth largest element in the [leetcode] array [215]
Local dealers play the community group purchase mode and share millions of operations
boot actuator - prometheus使用
随机推荐
Freshman learning sharing
go 4种单例模式
AES高级加密协议的动机阐述
Storage unit conversion
地平线2022年4月最新方案介绍
杰理之、产线装配环节【篇】
Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
位的高阶运算
Kubernetes uses the host name to allocate the pod on the specified node
The kth largest element in the [leetcode] array [215]
Solve the error of changing the selected file when uploading excel file. Net:: err_ UPLOAD_ FILE_ CHANGED
Jerry's prototype will trigger shutdown after multiple touches [chapter]
静态文件显示问题
LeetCode 968. Monitor binary tree
Local dealers play the community group purchase mode and share millions of operations
Learning Websites commonly used by circuit designers
Odoo13 build a hospital HRP environment (detailed steps)
移动端 1px 像素兼容性问题,实现1px 边框
严守工期,确保质量,这家AI数据标注公司做到了!
Chow-Liu Tree