当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jquery使用jxl插件导出excel示例

jquery使用jxl插件导出excel示例

2018年02月07日  | 移动技术网IT编程  | 我要评论
代码如下: function formattable(tableHtml, sheetName) { var template = '<html xmlns:

代码如下:


function formattable(tableHtml, sheetName) {
var template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="https://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table>{table}</table></body></html>';
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];
});
}

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网