//Export to Excel, note that there must be no comments in the table mark, because the childNodes will also count the comments //If an error occurs, you need to close Excel, otherwise the Excel process will keep running //There can only be one input value in td //There cannot be a structure in non-td, otherwise a missing ";" error will be reported //Add //Add button //Set the id and class of the table table to 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("Missing table object"); 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;ivar td = t.childNodes[0].childNodes[i]; if(parseInt(td.colSpan)>1){ cols = parseInt(td.colSpan); } else { cols ; } } try{ var oXL = new ActiveXObject("Excel.Application"); }catch(e){ alert(" Please confirm that Excel has been installed and allowed to run Excel!"); alert("Excel cannot be started, please ensure that Excel has been installed on the computer!nn If Excel has been installed," "Please add the IP address to the trusted site, And adjust the security level of IE trusted sites.
\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;
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn