jquery使用jxl插件导出excel示例_Javascript教程-查字典教程网
jquery使用jxl插件导出excel示例
jquery使用jxl插件导出excel示例
发布时间:2016-12-30 来源:查字典编辑
摘要:复制代码代码如下:functionformattable(tableHtml,sheetName){vartemplate='{table}...

复制代码 代码如下:

function formattable(tableHtml, sheetName) {

var template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><><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];

});

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类