//<script type="text/javascript" src="https://oss.sheetjs.com/sheetjs/xlsx.full.min.js"></script>
//excel/csv
<template>
<input type="file" @change="onFileChange" />
</template>
export default {
methods: {
onFileChange(event) {
this.file = event.target.files ? event.target.files[0] : null;
if (this.file) {
const reader = new FileReader();
reader.onload = (e) => {
/* Parse data */
const bstr = e.target.result;
const wb = XLSX.read(bstr, { type: 'binary' , cellDates: true, dateNF: 'yyyy/mm/dd;@'});
/* Get first worksheet */
const wsname = wb.SheetNames[0];
const ws = wb.Sheets[wsname];
/* Convert array of arrays */
const data = XLSX.utils.sheet_to_json(ws, { header: 1 });
console.log(data)
}
reader.readAsBinaryString(this.file);
}
},
}
};
//npm install read-excel-file --save
//excel file only
<template>
<input type="file" @change="onFileChange" />
</template>
import readXlsxFile from 'read-excel-file'
export default {
methods: {
onFileChange(e) {
var file = e.target.files ? e.target.files[0] : null;
readXlsxFile(file).then((data) => {
console.log(data)
})
}
}
}