1
我想用JavaScript
读取excel文件。众所周知,IE支持以下逻辑来读取。可以通过Ajax请求读取excel表格
var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("attachData.xlsx");
var excel_sheet = excel.Worksheets("Sheet1");
repCount = excel_sheet.Cells(cell,row).Value;
document.getElementById('div1').innerText = repCount;
但我想让它跨浏览器。由于上述代码行在其他浏览器中不起作用,所以我在考虑使用Ajax请求。我试图与下面的代码段:
var xhr = new XMLHttpRequest();
xhr.open('POST','../attachData.xlsx',true);
xhr.send();
xhr.onreadystatechange= readystatechange;
function readystatechange(){
if(xhr.readyState === 4){
console.log(xhr.response);
}
}
这里,响应来自unreadable
格式(如encoded
)。是有任何其他方式来实现这一点。我最关心的是,我们可以阅读Ajax吗?