antd导入excel

<a-upload accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
:beforeUpload="beforeUpload" @change="handleFileChange">
	<a-button type="primary">导入Excel</a-button>
</a-upload>

methods:
//导入excel
beforeUpload(file){
	let _this = this
	return new Promise(function(resolve, reject){
	// readExcel方法也使用了Promise异步转同步,此处使用then对返回值进行处理
		_this.readExcel(file).then(result => {
		// 此时标识校验成功,为resolve返回
			if (result) resolve(result)
		})
	})
},
//解析Excel
readExcel(file) {
	let _this = this
	return new Promise(function (resolve, reject) {// 返回Promise对象
		const reader = new FileReader()
		reader.onload = (e) => {// 异步执行
			try {
				// 以二进制流方式读取得到整份excel表格对象
				let data = e.target.result, workbook = XLSX.read(data, {type: 'binary'})
				const exlname = workbook.SheetNames[0] // 取第一张表
				const exl = XLSX.utils.sheet_to_json(workbook.Sheets[exlname]) // 生成json表格内容
                console.log(exl)
                let arr = []
                exl.map((v, i) => {
                     let obj = {}
                     //对获取的Excel数据进行操作
                     arr.push(obj)
                })
                _this.dataSource = arr
                resolve()
			} catch (e) {
				reject(e.message)
			}
		}
		reader.readAsBinaryString(file)
	})
},

vue实现Excel导入
https://blog.csdn.net/sinat_35538827/article/details/101444051
https://blog.csdn.net/qq_41348029/article/details/84584276
文件类型:
https://blog.csdn.net/usuallyuser/article/details/83060341
Excel限制文本长度
http://www.veryhuo.com/a/view/80048.html
Excel设置下拉选项
https://baijiahao.baidu.com/s?id=1599864933052928528&wfr=spider&for=pc

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值