jquery使用jxl插件導(dǎo)出excel示例
更新時(shí)間:2014年04月14日 15:42:50 作者:
這篇文章主要介紹了jquery使用jxl插件導(dǎo)出excel的具體實(shí)現(xiàn)步驟,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
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];
});
}
相關(guān)文章
JQuery 插件模板 制作jquery插件的朋友可以參考下
JQuery 插件模板 制作jquery插件的朋友可以參考下2010-03-03
jquery post方式傳遞多個(gè)參數(shù)值后臺(tái)以數(shù)組的方式進(jìn)行接收
在用jquery的post方式傳遞多個(gè)值時(shí),在后臺(tái)頁(yè)面可以用數(shù)組形式接收,很不錯(cuò)吧,可以接收多個(gè)值啊,接下來(lái)介紹實(shí)現(xiàn)方法,感興趣的朋友可以了解下哦2013-01-01
JQuery 實(shí)現(xiàn)的頁(yè)面滾動(dòng)時(shí)浮動(dòng)窗口控件
JQuery 實(shí)現(xiàn)的頁(yè)面滾動(dòng)時(shí)浮動(dòng)窗口控件實(shí)現(xiàn)代碼,大家可以參考下。2009-07-07

