jquery使用jxl插件导出excel示例

2019-12-21,,,

复制代码 代码如下:
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><!--[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];
});
}

您可能感兴趣的文章:

  • jxl操作excel写入数据不覆盖原有数据示例
  • java创建excel示例(jxl使用方法)
  • android通过jxl读excel存入sqlite3数据库
  • Java使用jxl包写Excel文件适合列宽实现
  • 通过jxl.jar 读取、导出excel的实例代码
  • java 中JXL操作Excel实例详解

《jquery使用jxl插件导出excel示例.doc》

下载本文的Word格式文档,以方便收藏与打印。