Reputation: 2135
Tried doing
var work = XLSX.readFile("D:\\sched.xls"); //var XLSX = <XLSX>require('xlsx');
But I believe I am having the issues described in this issue.
https://github.com/stephen-hardy/xlsx.js/issues/11
EDIT BEGIN
Found that I was actually using a different library then the one that I found the issue listed with.
https://github.com/SheetJS/js-xlsx/issues/135
EDIT END
The workaround is "read file with base64 encoding, then passing it to xlsx does it."
var fileRead = fs.readFileSync("D:\\sched.xls");
var base64 = fileRead.toString('base64');
//The workaround seems to be talking about some xlsx function?
//even .read doesn't seem to be thing based on my typescript binding.
var workbook = XLSX.read(base64); //to use read switch:
// var XLSX = <XLSX>require('xlsx');
// var XLSX = require('xlsx')
So I'm pretty sure I have read in the file using base64 encoding how do I pass that into xlsx.js
Upvotes: 0
Views: 10075
Reputation: 250942
You need to use an Excel reader that supports ".xls" format. For example, excel-parser library supports both ".xls" and ".xlsx" formats.
I don't know what library you are using, but given it is called XLSX
, I expect it can only parse the modern ".xlsx" format and not the older ".xls" format (and your file has an ".xls" extension).
var excelParser = require('excel-parser');
excelParser.worksheets({
inFile: 'D:\\sched.xls'
}, function(err, worksheets){
if(err) {
console.error(err);
}
console.log(worksheets);
});
Would give you the output in a format such as this:
[
['ID', 'Name', 'Location'],
['1757491', 'Travis', 'Philadelphia'],
['75525', 'Steve', 'UK']
]
Upvotes: 1