//匯出到Excel,注意,表格標記內不得有註釋,因為childNodes會把註釋也算進去
//如果出錯,需要關閉Excel,否則Excel進程會一直運行
//td中只能有一個input值
//非td間不可以有組成否則報缺少“;”錯誤
//引用頁加上
//新增按鈕
//將table表的id和class設定為tableNr
function ExportExcel(btn,TabId,strCols,sTitle,sHeader,sFooter){
//alert('ssss');
btn.style.cursor = "wait";
event.returnValue = false;
//try{
var tab = document.getElementById( TabId);
// if(tab == null) tab = document.getElementById("dg")
//if(tab == null) tab = document.getElementById("db")
//if(tab == null) tab = document.getElementById(TabId)
if(tab == null){
alert("缺少表格物件");
btn.style.cursor = " hand";
return;
}
var t = tab.firstChild;
var rows = t.childNodes.length;
//alert(t.nodeName); //test
var tds = t.childNodes[0].childNodes.length;
var cols = 0;
for(var i=0;i
var td = t.Nodechilds [0].childNodes[i];
if(parseInt(td.colSpan)>1){
cols = parseInt(td.colSpan);
}
else{
cols ;
}
}
try{
var oXL = new ActiveXObject("Excel.Application");
}catch(e){
alert("請確認已經安裝了Excel並允許執行Excel!");
alert("無法啟動Excel,請確保電腦中已經安裝了Excel!nn如果已經安裝了Excel," "請將ip位址加入信任站點,並調整IE信任站點的安全等級。
\n具体操作:
\n"+"工具 → Internet选项 → 安全 → 自定义级别 → ActiveX 控件和插件 → 对未标记为可安全执行脚本的ActiveX 控件初始化并执行脚本 → 启用 → 确定");
btn.style.cursor = "hand";
return;
}
oXL.Workbooks.Add();
var obook = oXL.ActiveWorkBook;
var osheets = obook.Worksheets;
var osheet = obook.Sheets(1);
var xlrow = 1;
//添加标题
if((sTitle == "") || (typeof(sTitle)=="undefined") || (sTitle==null)){
var t_tdHeadc = document.getElementById("tdHeadc");
if(t_tdHeadc != null){
sTitle = t_tdHeadc.innerText;
var sk = sTitle.lastIndexOf("-->")+3;
sTitle = sTitle.substring(sk);
}
}
osheet.Cells(1, 1) = sTitle;
osheet.Range(osheet.Cells(xlrow, 1),osheet.Cells(xlrow,cols)).Select(); //选择该列
oXL.Selection.HorizontalAlignment = 3; //居中
oXL.Selection.MergeCells = true;
xlrow++;
//小标题
if((sHeader == "") || (typeof(sHeader)=="undefined") || (sHeader==null)){
sHeader = "";
}
if(sHeader != ""){
osheet.Cells(2, 1) = sHeader;
osheet.Range(osheet.Cells(xlrow, 1),osheet.Cells(xlrow,cols)).Select(); //选择该列
//oXL.Selection.HorizontalAlignment = 3; //居中
oXL.Selection.MergeCells = true;
xlrow++;
}
var winX = (screen.width - 300) / 2;
var winY = (screen.height - 120) / 2;
var win = window.open("","","directories=0,location=0,memubar=0,scrollbars=0,status=0,toolbar=0,width=230,height=75,left=" + winX + ",top=" + winY);
win.document.write('' + sTitle + '导出Excel');
win.document.write(' | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ');
win.document.write('
总计' + rows + '行,已导出行!
>var osx=document.getElementById("sx");var div = document.getElementById("m_pub_wzs_progress_x ");docfunction m_pub_wfunction ,pCurrCount){osx.innerText = pCurrCount;var m = Math.floor(pCurrCount / pTotalCount * 30);div.style.display = "";var tr = div.firstChild.rows[0 ];for(var i= 0;i