当前位置:网站首页>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);
边栏推荐
- 數據分析學習記錄--用EXCEL完成簡單的單因素方差分析
- uniapp微信登录返显用户名和头像
- World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
- go 4種單例模式
- 【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等
- go 多线程数据搜索
- 移动端 1px 像素兼容性问题,实现1px 边框
- 中国信通院、清华大学、腾讯安全,云原生安全产学研用强强联合!
- [LeetCode] 回文数【9】
- 傑理之修改不需要長按開機功能【篇】
猜你喜欢

海思3559万能平台搭建:在截获的YUV图像上旋转操作

Qt QScrollArea

Mask R-CNN

地平线2022年4月最新方案介绍

全面解析分享购商业模式逻辑?分享购是如何赋能企业

Odoo13 build a hospital HRP environment (detailed steps)

MySQL reset password, forget password, reset root password, reset MySQL password

E-commerce system microservice architecture

Jatpack------LiveData

解决Chrome浏览器和Edeg浏览器主页被篡改的方法
随机推荐
go 4種單例模式
pytorch训练CPU占用持续增长(bug)
[leetcode] reverse string [344]
Distributed monitoring system ZABBIX
DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!
损失函数~
P1007 single log bridge
boot actuator - prometheus使用
kubernetes 使用主机名将 pod 分配在指定节点上
首批 | 腾讯云完成国内首个云原生安全成熟度评估
杰理之样机在多次触摸后会触发关机【篇】
[leetcode] most elements [169]
杰理之快速触摸不响应问题【篇】
分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少
[leetcode] number of palindromes [9]
[LeetCode] 存在重复元素【217】
LC173. 二叉搜索树迭代器
go 多线程数据搜索
Go condition variable
位的高阶运算