Struggling with reading excel files in vue.js as the memory usage spikes to 5GB after processing a small file. Need help converting the file to JSON format. Tried various options mentioned in the documentation but encountered different errors. Also checked a similar query here without success.
- base64: "TypeError: input.replace is not a function"
- binary: "TypeError: x.charCodeAt is not a function"
- string: "TypeError: data.match is not a function"
- array: causing memory spike up to 5GB
Attempted to use FileReader as per documentation, however, unable to get it working properly as functions return empty results.
Both methods yielded similar outcomes:
<v-file-input
v-on:change="displayFile($event)"
v-model="file">
</v-file-input>
<input type="file" name="xlfile" id="xlf" v-on:change="displayFile($event)" />
displayFile: function (event) {
console.log(this.file)
this.file.text().then(text => {
const fileType = this.file.type
console.log(fileType)
})
const reader = new FileReader()
reader.onload = (data) => {
const workbook = XLSX.read(data, {
type: 'buffer'
})
workbook.SheetNames.forEach(function (sheetName) {
const XLRowObject = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName])
const jsonObject = JSON.stringify(XLRowObject)
})
}
reader.onerror = function (ex) {
console.log(ex)
}
reader.readAsText(this.file)
}