首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

兼容红狐 IE 的-导出Excel

2013-10-12 
兼容火狐 IE 的---导出Excel/** 导出Excel*/var exportTab (function() {var uri data:application/v

兼容火狐 IE 的---导出Excel

/** 导出Excel*/var exportTab = (function() {  var uri = 'data:application/vnd.ms-excel;base64,';  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></head><body><table>{table}</table></body></html>';    var base64 = function(s) {return window.btoa(unescape(encodeURIComponent(s))) };    var format = function(s, c) {return s.replace(/{(\w+)}/g,function(m, p) {return c[p]; }) };var explorer = window.navigator.userAgent ;if (explorer.indexOf("MSIE") >= 0) {return function(table,name){var curTbl = document.getElementById("listtable");     var oXL = new ActiveXObject("Excel.Application");     //创建AX对象excel     var oWB = oXL.Workbooks.Add();     //获取workbook对象    var oSheet = oWB.ActiveSheet;    //激活当前sheet     var Lenr = curTbl.rows.length;     //取得表格行数     for (i = 0; i < Lenr; i++)     {         var Lenc = curTbl.rows(i).cells.length;         //取得每行的列数         for (j = 0; j < Lenc; j++)         {             oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText;             //赋值         }     }     oXL.Visible = true;     //设置excel可见属性}}else{return function(table, name) {    if (!table.nodeType) table= document.getElementById(table)    var ctx = {worksheet: name|| 'Worksheet', table: table.innerHTML}    alert(table.innerHTML);    window.location.href = uri+ base64(format(template, ctx))  }}})();

热点排行