当前位置:网站首页>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);
边栏推荐
猜你喜欢
地平线2022年4月最新方案介绍
容器化技术在嵌入式领域的应用
地方经销商玩转社区团购模式,百万运营分享
Local dealers play the community group purchase mode and share millions of operations
Lambda表达式:一篇文章带你通透
`Usage of ${}`
[leetcode] most elements [169]
The motivation of AES Advanced Encryption Protocol
【硬件】标准阻值的由来
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
随机推荐
Baidu AI Cloud - create a face recognition application
MySQL查询附近的数据.并按距离进行排序.
创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
Niuke: Dragon and dungeon games
悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖
[leetcode] reverse string [344]
Local dealers play the community group purchase mode and share millions of operations
[LeetCode] 数组中的第K个最大元素【215】
Qt QScrollArea
Data analysis learning records -- complete a simple one-way ANOVA with Excel
分布式监控系统zabbix
Jerry's built-in short press and long press, no matter how long it is, it is a short press [chapter]
Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]
严守工期,确保质量,这家AI数据标注公司做到了!
Golang's learning route
PMP project integration management
Go 4 modes Singleton
送给即将工作的自己
Webrtc audio and video capture and playback examples and mediastream media stream analysis
情感对话识别与生成简述