![](https://i-blog.csdnimg.cn/blog_migrate/c605a27a8604413f8fc8eb45c9080f60.png)
表格中的时间为2023/2/16
调用 XLSX.utils.sheet_to_json 读取到的时间为2/16/23
![](https://i-blog.csdnimg.cn/blog_migrate/859864bc0f15b59c8e763d48937a9b72.png)
时间格式不对-期待的时间格式为2023-02-16 00:00
增加代码 cellDates: true, dateNF: "yyyy-MM-dd HH:mm" 解决问题
readerData (rawFile) {
this.loading = true
this.isFile = true // 流程结束后,重置,让下次上传重新校验
this.result = false
return new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onload = e => {
const data = e.target.result
const workbook = XLSX.read(data, { type: 'array', cellDates: true, dateNF: "yyyy-MM-dd HH:mm" })
const firstSheetName = workbook.SheetNames[0]
const worksheet = workbook.Sheets[firstSheetName]
const header = this.getHeaderRow(worksheet)
if (header[0] != "SN" || header[1] != "密钥" || header[2] != "二维码URL" || header[3] != "IMEI" || header[4] != "软件版本" || header[5] != "硬件版本" || header[6] != "生产时间") {
this.$message.error('导入文件模板格式错误')
this.isFile = false
}
if (this.isFile) {
const results = XLSX.utils.sheet_to_json(worksheet, { raw: false })
console.log("results", results)
this.generateData({ header, results })
}
this.loading = false
resolve()
}
if (this.isFile) {
reader.readAsArrayBuffer(rawFile)
}
})
},
excel单元格格式需要为 *2012/3/14
![](https://i-blog.csdnimg.cn/blog_migrate/275b703fa0405028c962119d4b786b5d.png)