我试图从excel文件中获取工作表列表,以便在组合框中显示它。这样的想法是,用户可以从excel文件中选择要导入的文件,而不必键入文件,从而避免输入错误
function getSheets(file)
{
var reader;
reader = new FileReader();
reader.onload = function(e)
{
var data;
var workbook;
var sheets;
data = e.target.result();
workbook = XLSX.read(data, {type: 'binary'});
sheet = workbook.SheetNames;
for (var i in sheets.items)
{
console.log(sheets.items[i].name);
}
}
reader.onerror = function(ex)
{
console.log(ex);
}
reader.readAsBinaryString(file);
}
执行该功能时显示以下错误:
Function expected
行:data = e.target.result();
我应该怎么面对吗?
答案 0 :(得分:0)
详细说明见Here
sheet.forEach(function (y) { /*Iterate through all sheets*/
/*Convert the cell value to Json*/
var exceljson = XLSX.utils.sheet_to_json(workbook.Sheets[y]);
});