当前位置:网站首页>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);
边栏推荐
- Jericho's thimble reaction when directly touching the prototype is abnormal [chapter]
- Golang面试整理 三 简历如何书写
- MySQL reset password, forget password, reset root password, reset MySQL password
- go 条件变量
- Graphic view frame
- 移动端 1px 像素兼容性问题,实现1px 边框
- odoo13搭建医院HRP环境(详细步骤)
- 容器化技术在嵌入式领域的应用
- [LeetCode] 数组中的第K个最大元素【215】
- Wait to solve the zombie process
猜你喜欢
![加油站[问题分析->问题转换->贪心]](/img/15/5313f900abedb46ce82d8ab81af1d7.png)
加油站[问题分析->问题转换->贪心]

Niuke: Dragon and dungeon games

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

Addition, deletion, modification and query of handwritten ORM (object relationship mapping)

【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?

Niuke network: maximum submatrix

严守工期,确保质量,这家AI数据标注公司做到了!

最小生成树 Minimum Spanning Tree

解决Chrome浏览器和Edeg浏览器主页被篡改的方法

P1007 独木桥
随机推荐
Hanging mirror security won four global infosec awards on rsac2022
Jericho's thimble reaction when directly touching the prototype is abnormal [chapter]
加油站[问题分析->问题转换->贪心]
杰理之如何测试按键的误触率【篇】
Stop slave is stuck -- the event of the transaction is not copied completely
xshell配置xforward转发火狐浏览器
剑指 Offer II 099. 最小路径之和-双百代码
解决Chrome浏览器和Edeg浏览器主页被篡改的方法
[LeetCode] 反转字符串中的单词 III【557】
[Solved] Splunk: Cannot get username when all users are selected“
【硬件】标准阻值的由来
Boot actuator - Prometheus use
Data analysis learning records -- complete a simple one-way ANOVA with Excel
Xshell configuration xforward forwarding Firefox browser
Uniapp wechat login returns user name and Avatar
中国信通院、清华大学、腾讯安全,云原生安全产学研用强强联合!
easyclick,ec权朗网络验证源码
odoo13搭建医院HRP环境(详细步骤)
Go condition variable
uniapp微信登录返显用户名和头像