Sheetnames using URL.createObjectURL does not work
I'm using XLSX to extract the sheetnames and it returns "Sheet1"
So when i try to extract the data (using alasql) i get the error "Cannot read !ref of undefined" (or something like that)
The excell file is made in a dutch excell though and apparently it should get "Blad1" instead of "Sheet1"
let fileAsObject = URL.createObjectURL( file );
let workbook = XLSX.read(fileAsObject);
console.log(workbook.SheetNames);
Does anyone know how to fix this?
Edit: It's really weird, if i use Blad1 it starts to read it, but if i console.log the workbook i get the following
SheetNames: Array(1)
0: "Sheet1"
Sheets:
Sheet1:
!ref: "A1"
A1:
t: "s"
v: "nZÛi³ÿæÉÖ¢³'(Ê&uëõýÿ\ÛÍáÎzãëÎZÛ¼ë~}wä"
Ok i'm still diving into this. And now it seems that even if I make an XLSX with sheetnames, it never returns them but always returns the above.
Ok i might need to read it differently, don't know how, it works for alaSql to use file as object.
I'm still using that for alaSql. But to get the sheetnames i've changed it to:
reader.onload = function() {
let workbook = XLSX.read(reader.result, {type: 'binary'});
console.log(workbook.SheetNames);
};
reader.readAsBinaryString(file);
To read from an object URL, you have to use XHR or fetch to get the data as an array buffer:
fetch(url).then((blob) =>> blob.arrayBuffer()).then((ab) => {
var u8 = new Uint8Array(ab);
let workbook = XLSX.read(ab, {type: 'array'});
console.log(workbook.SheetNames);
});