no message
Former-commit-id: ab8cdf355d876072816aa4ba63109ae0efe44fcb Former-commit-id: 149582030e374d7a34465012488458bfe0ce46ff Former-commit-id: 49475fb078ac142e903189e6e8d8fff4c0847a96
This commit is contained in:
parent
691a47cc78
commit
7107c76c25
|
|
@ -1,7 +1,7 @@
|
|||
/* eslint-disable */
|
||||
// 库
|
||||
import papa from 'papaparse'
|
||||
import XLSX from 'xlsx'
|
||||
import xlsx from 'xlsx'
|
||||
export default {
|
||||
install (Vue, options) {
|
||||
Vue.prototype.$import = {
|
||||
|
|
@ -31,13 +31,13 @@ export default {
|
|||
}
|
||||
const getHeaderRow = sheet => {
|
||||
const headers = []
|
||||
const range = XLSX.utils.decode_range(sheet['!ref'])
|
||||
const range = xlsx.utils.decode_range(sheet['!ref'])
|
||||
let C
|
||||
const R = range.s.r
|
||||
for (C = range.s.c; C <= range.e.c; ++C) {
|
||||
var cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })]
|
||||
var cell = sheet[xlsx.utils.encode_cell({ c: C, r: R })]
|
||||
var hdr = 'UNKNOWN ' + C
|
||||
if (cell && cell.t) hdr = XLSX.utils.format_cell(cell)
|
||||
if (cell && cell.t) hdr = xlsx.utils.format_cell(cell)
|
||||
headers.push(hdr)
|
||||
}
|
||||
return headers
|
||||
|
|
@ -45,11 +45,11 @@ export default {
|
|||
reader.onload = e => {
|
||||
const data = e.target.result
|
||||
const fixedData = fixdata(data)
|
||||
const workbook = XLSX.read(btoa(fixedData), { type: 'base64' })
|
||||
const workbook = xlsx.read(btoa(fixedData), { type: 'base64' })
|
||||
const firstSheetName = workbook.SheetNames[0]
|
||||
const worksheet = workbook.Sheets[firstSheetName]
|
||||
const header = getHeaderRow(worksheet)
|
||||
const results = XLSX.utils.sheet_to_json(worksheet)
|
||||
const results = xlsx.utils.sheet_to_json(worksheet)
|
||||
resolve({header, results})
|
||||
}
|
||||
reader.readAsArrayBuffer(file)
|
||||
|
|
|
|||
Loading…
Reference in New Issue