当前位置:网站首页>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环境(详细步骤)
- 杰理之样机无触摸,拆机之后重新安装变正常【篇】
- 地方经销商玩转社区团购模式,百万运营分享
- Jerry's fast touch does not respond [chapter]
- 海思3559万能平台搭建:在截获的YUV图像上旋转操作
- 分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少
- Il n'est pas nécessaire d'appuyer longtemps sur la fonction de démarrage pour modifier Jelly [chapitre]
- 解决Chrome浏览器和Edeg浏览器主页被篡改的方法
- Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月1日08:43:06
猜你喜欢
随机推荐
[leetcode] reverse string [344]
Chow-Liu Tree
从2022年Q1财报看携程的韧性和远景
泛型与反射,看这篇就够了
Jerry's prototype will trigger shutdown after multiple touches [chapter]
电路设计者常用的学习网站
[chestnut sugar GIS] ArcScene - how to make elevation map with height
[Luogu p1541] tortoise chess [DP]
成功改变splunk 默认URL root path
Storage unit conversion
杰理之样机在多次触摸后会触发关机【篇】
AES高級加密協議的動機闡述
分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少
kubernetes 使用主机名将 pod 分配在指定节点上
[LeetCode] 存在重复元素【217】
Stop slave is stuck -- the event of the transaction is not copied completely
【硬件】标准阻值的由来
go 4種單例模式
Introduction and response to high concurrency
容器化技术在嵌入式领域的应用



![[chestnut sugar GIS] how does global mapper batch produce ground contour lines through DSM](/img/5d/c23ec16df6ce8d78207b635f59dc20.png)




