Open panavsethi1 opened 4 years ago
Can you send the entire error log along with the Node.js version you are using?
I have the same Problem. The reason seems to be that clientside js cant use the fs(FileSystem).
Here is the same issue with another package: https://github.com/SheetJS/sheetjs/issues/418
According to the Answers there, the Problem can be solved by using a html Input tag and reading the file that way. But i have not tried it yet.
I hope that helps.
It works! But the code has to be modified. I added a posibiliy to pass a "type" argument to the underlying xlsx package.
My code looks like this:
const onChange = (e) => {
const reader = new FileReader();
reader.onloadend = function (event) {
console.log(event.target.result);
const tmp = excelToJson({ source: event.target.result });
console.log(tmp);
};
reader.readAsArrayBuffer(e.target.files[0]);
};
<input type="file" onChange={onChange} />
and the change in convert-excel-to-json.js looks like this:
if (_config.source) {
workbook = XLSX.read(_config.source, {
type:"buffer",
sheetStubs: true,
cellDates: true
});
Final edit:
Henrik's change in convert-excel-to-json.js also works for me, with a slight variation on where the array buffer comes from:
with this.file coming from a standard HTML file picker:
this.file.arrayBuffer()
.then(buffer => {
const batchJson = excelToJson({
source: buffer,
header: { rows: 1 },
columnToKey: { '*': '{{columnHeader}}' }
})
})
}```
It works! But the code has to be modified. I added a posibiliy to pass a "type" argument to the underlying xlsx package.
My code looks like this:
const onChange = (e) => { const reader = new FileReader(); reader.onloadend = function (event) { console.log(event.target.result); const tmp = excelToJson({ source: event.target.result }); console.log(tmp); }; reader.readAsArrayBuffer(e.target.files[0]); }; <input type="file" onChange={onChange} />
and the change in convert-excel-to-json.js looks like this:
if (_config.source) { workbook = XLSX.read(_config.source, { type:"buffer", sheetStubs: true, cellDates: true });
This worked for me as well. Thank you!
Works perfect!!! @DiegoZoracKy Could commit the change pls?
This shows up while following the simple steps in npm documentation