示例代码:
function tableToExcel() {
var tbody = '<tr><th>序号</th><th>说明<th/></tr><tr><td>1</td><td>测试</td></tr>';
var html="<html><head><meta charset='UTF-8'></head><body><table>"+tbody+"</table></body></html>"
var excelBlob = new Blob([html], {type: 'application/vnd.ms-excel'});
var fileName = "文件名.xls";
if(!!window.ActiveXObject || "ActiveXObject" in window){
//IE浏览器
window.navigator.msSaveOrOpenBlob(excelBlob,fileName);
}else{
var oa = document.createElement('a');
oa.href = URL.createObjectURL(excelBlob);
oa.download = fileName;
document.body.appendChild(oa);
oa.click();
}
}
网友评论