no message
Former-commit-id: ab8cdf355d876072816aa4ba63109ae0efe44fcb Former-commit-id: 149582030e374d7a34465012488458bfe0ce46ff Former-commit-id: 49475fb078ac142e903189e6e8d8fff4c0847a96
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
// 库
|
// 库
|
||||||
import papa from 'papaparse'
|
import papa from 'papaparse'
|
||||||
import XLSX from 'xlsx'
|
import xlsx from 'xlsx'
|
||||||
export default {
|
export default {
|
||||||
install (Vue, options) {
|
install (Vue, options) {
|
||||||
Vue.prototype.$import = {
|
Vue.prototype.$import = {
|
||||||
@@ -31,13 +31,13 @@ export default {
|
|||||||
}
|
}
|
||||||
const getHeaderRow = sheet => {
|
const getHeaderRow = sheet => {
|
||||||
const headers = []
|
const headers = []
|
||||||
const range = XLSX.utils.decode_range(sheet['!ref'])
|
const range = xlsx.utils.decode_range(sheet['!ref'])
|
||||||
let C
|
let C
|
||||||
const R = range.s.r
|
const R = range.s.r
|
||||||
for (C = range.s.c; C <= range.e.c; ++C) {
|
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
|
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)
|
headers.push(hdr)
|
||||||
}
|
}
|
||||||
return headers
|
return headers
|
||||||
@@ -45,11 +45,11 @@ export default {
|
|||||||
reader.onload = e => {
|
reader.onload = e => {
|
||||||
const data = e.target.result
|
const data = e.target.result
|
||||||
const fixedData = fixdata(data)
|
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 firstSheetName = workbook.SheetNames[0]
|
||||||
const worksheet = workbook.Sheets[firstSheetName]
|
const worksheet = workbook.Sheets[firstSheetName]
|
||||||
const header = getHeaderRow(worksheet)
|
const header = getHeaderRow(worksheet)
|
||||||
const results = XLSX.utils.sheet_to_json(worksheet)
|
const results = xlsx.utils.sheet_to_json(worksheet)
|
||||||
resolve({header, results})
|
resolve({header, results})
|
||||||
}
|
}
|
||||||
reader.readAsArrayBuffer(file)
|
reader.readAsArrayBuffer(file)
|
||||||
|
|||||||
Reference in New Issue
Block a user