import * as xlsx from 'xlsx'
// 读取Excel文件
function readFile(file) {
return new Promise((resolve, reject) => {
let reader = new FileReader()
reader.readAsBinaryString(file)
reader.onload = ev => {
resolve(ev.target.result)
}
})
}
class Home extends React.Component {
onChange = async (info) => {
if (info.file.status !== 'uploading') {
const data = await readFile(info.file.originFileObj)
const work = xlsx.read(data, { type: 'binary' })
console.log(work) // Excel 内容
}
}
render() {
return <Row>
<Upload
name={'file'}
action={''}
onChange={this.onChange}
>
<Button>
<Icon type="upload" /> Click to Upload
</Button>
</Upload>
</Row>
}
}
前端antd-version 3.xx配合xlsx插件库,前端js读取excel文件内容
最新推荐文章于 2024-07-06 16:47:02 发布