简体   繁体   中英

How to load XLS file into javascript using js-xls

I have a input type=file and I'm trying to have js-xls load it.

<input ngf-select ng-model="mypage.myfile" type="file" id="file_input" name="myfile" >

Here are three different ways I've tried to load the file in my controller:

var workbook = XLS.readFile(mypage.myfile);

It says:

TypeError: Cannot read property 'readFileSync' of undefined

I also tried this:

var workbook = XLS.read(mypage.myfile, {type:"binary"});

And get:

TypeError: f.charCodeAt is not a function

And finally:

var workbook = XLS.read(mypage.myfile.toString(), {type:"binary"});

And get:

Error: Unsupported file 91

I verified each time that the mypage.myfile is actually there and what I expect.

Ok this ended up being the answer: https://stackoverflow.com/a/37083658/13009

I changed the XLSX to XLS which I think will handle both. I also removed the outer function, I'm not sure what it was doing, and added a callback to do the actual work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM