当前位置: 编程技术>WEB前端
jquery使用jxl插件导出excel示例
来源: 互联网 发布时间:2014-08-25
本文导语: 代码如下: function formattable(tableHtml, sheetName) { var template = '{table}'; var ctx = { worksheet : name, table : tableHtml }; var downloadLink = document.createElement("a"); downloadLink.href = 'data:application/vnd.ms-excel;base64,' + base64(format( template, ctx)); downloadLink.downlo...
代码如下:
function formattable(tableHtml, sheetName) {
var template = '{table}';
var ctx = {
worksheet : name,
table : tableHtml
};
var downloadLink = document.createElement("a");
downloadLink.href = 'data:application/vnd.ms-excel;base64,' + base64(format(
template, ctx));
downloadLink.download = sheetName + ".xls";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
// window.open('data:application/vnd.ms-excel;base64,'+
// base64(format(template, ctx)));
}
function base64(s) {
return $.base64.btoa(unescape(encodeURIComponent(s)));
}
var format = function(s, c) {
return s.replace(/{(w+)}/g, function(m, p) {
return c[p];
});
}