当前位置:Gxlcms > JavaScript > jquery使用jxl插件导出excel示例_jquery

jquery使用jxl插件导出excel示例_jquery

时间:2021-07-01 10:21:17 帮助过:16人阅读

代码如下:

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];
});
}

人气教程排行