[英]Use XLSX.js with base64
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 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 https://github.com/SheetJS/js-xlsx/issues/135编辑结束
The workaround is "read file with base64 encoding, then passing it to xlsx does it." 解决方法是“读取具有base64编码的文件,然后将其传递给xlsx。”
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 所以我很确定我已经使用base64编码读取了文件,如何将其传递给xlsx.js
You need to use an Excel reader that supports ".xls" format. 您需要使用支持“ .xls”格式的Excel阅读器。 For example, excel-parser library supports both ".xls" and ".xlsx" formats.
例如, excel-parser库同时支持“ .xls”和“ .xlsx”格式。
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). 我不知道您使用的是什么库,但是给定的名称是
XLSX
,我希望它只能解析现代的“ .xlsx”格式,而不能解析较旧的“ .xls”格式(并且您的文件具有“ .xls”延期)。
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']
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.