当前位置:网站首页>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);
边栏推荐
- odoo13搭建医院HRP环境(详细步骤)
- 悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖
- [chestnut sugar GIS] how does global mapper batch produce ground contour lines through DSM
- 从2022年Q1财报看携程的韧性和远景
- Storage unit conversion
- Jatpack------LiveData
- 地方经销商玩转社区团购模式,百万运营分享
- The motivation of AES Advanced Encryption Protocol
- Graphic view frame
- Golang interview finishing three resumes how to write
猜你喜欢

PMP project integration management

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

QT qsplitter splitter

Performance optimization - rigorous mode

WebRTC音视频采集和播放示例及MediaStream媒体流解析

Dahua cloud native load balancing article - the passenger flow of small restaurants has increased

PMP项目整合管理

boot actuator - prometheus使用

AES高级加密协议的动机阐述

Comprehensively analyze the logic of the shared purchase business model? How sharing purchase empowers Enterprises
随机推荐
Data analysis learning records -- complete a simple one-way ANOVA with Excel
Array advanced improvement
分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少
[chestnut sugar GIS] ArcScene - how to make elevation map with height
Odoo13 build a hospital HRP environment (detailed steps)
Go four singleton modes
Lambda表达式:一篇文章带你通透
QT qsplitter splitter
地方经销商玩转社区团购模式,百万运营分享
中国信通院、清华大学、腾讯安全,云原生安全产学研用强强联合!
LeetCode 968. Monitor binary tree
加油站[问题分析->问题转换->贪心]
Jerry's charge unplugged, unable to touch the boot [chapter]
Baidu AI Cloud - create a face recognition application
P1007 single log bridge
Splunk audit 的设定
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
Motivation du Protocole de chiffrement avancé AES
Jericho's thimble reaction when directly touching the prototype is abnormal [chapter]
[leetcode] reverse string [344]