ie9 html表格颜色,ie9兼容模式下可用,js导出table到excel

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

WEB页面导出为EXCEL文档的方法
WEB页面导出为EXCEL文档的方法
列标题1列标题2列标题3列标题4列标题5
aaabbbcccdddeee
AAABBBCCCDDDEEE
FFFGGGHHHIIIJJJ
妞妞
列标题1列标题2列标题3列标题5
AAABBBCCCEEE
FFFGGGHHHJJJ

导出

function exec(){

var tb=$("#tableExcel").html();

var tb1=$("#tableExcel1").html();

var tabhtml='

';

var cells1=$($("#tableExcel").find("tr")[1]).find("td").length;

var cells2=$($("#tableExcel1").find("tr")[1]).find("td").length;

$(".ww").html(tabhtml);

exportExcel('tableExcel2','name','WEB页面导出为EXCEL文档的方法.xls');

}

var idTmr;

function  getExplorer() {

var explorer = window.navigator.userAgent ;

//ie

if (explorer.indexOf("MSIE") >= 0|| (explorer.indexOf("Windows NT 6.1;") >= 0 && explorer.indexOf("Trident/7.0;") >= 0)) {

return 'ie';

}

//firefox

else if (explorer.indexOf("Firefox") >= 0) {

return 'Firefox';

}

//Chrome

else if(explorer.indexOf("Chrome") >= 0){

return 'Chrome';

}

//Opera

else if(explorer.indexOf("Opera") >= 0){

return 'Opera';

}

//Safari

else if(explorer.indexOf("Safari") >= 0){

return 'Safari';

}

}

function exportExcel(tableid,name,filename) {

//    alert(getExplorer());

if(getExplorer()=='ie') {

var curTbl = document.getElementById(tableid);

var oXL = new ActiveXObject("Excel.Application");

var oWB = oXL.Workbooks.Add();

var oSheet = oWB.ActiveSheet;

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;

}else{

tableToExcel(tableid,name,filename)

}

}

function Cleanup() {

window.clearInterval(idTmr);

CollectGarbage();

}

var tableToExcel = (function() {

var uri = 'data:application/vnd.ms-excel;base64,',

template = '

',

base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) },

format = function(s, c) {

return s.replace(/{(\w+)}/g,

function(m, p) { return c[p]; })

}

return function(table, name,filename) {

if (!table.nodeType) table = document.getElementById(table)

var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}

document.getElementById("dlink").href = uri + base64(format(template, ctx));

document.getElementById("dlink").download = filename;

document.getElementById("dlink").click();

}

})()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值