function copyToExcel(tableid) {
//Control button
var btn = document.getElementById("copy");
btn.setAttribute("disabled", "true");
btn.setAttribute("value", "Processing...");
var curTbl = document.getElementById(tableid);
try {
var oXL = new ActiveXObject("Excel.Application");
}
catch (e) {// If the IE security level is not set, an error will occur (Automation server cannot create objects)
/*
If Scripting.FileSystemObject (FSO text file reading and writing) is turned off, just turn on the FSO function, in "Run" Execute regsvr32 scrrun.dll
*/
alert("Excel cannot be started!nn If you are sure that Excel is already installed on your computer," "then please adjust the security level of IE.
nSpecific operations:
n" "Tools → Internet Options → Security → Custom Level → Initialize and script ActiveX not marked as safe → Enable");
return false;
}
var oWB = oXL.Workbooks .Add();
var oSheet = oWB.ActiveSheet;
var sel = document.body.createTextRange();
sel.moveToElementText(curTbl);
sel.select();
sel.execCommand("Copy");
oSheet.Paste();
oXL.Visible = true;
var fname = oXL.Application.GetSaveAsFilename("Export table to excel.xls", "Excel Spreadsheets (*.xls), *.xls");
oWB.SaveAs(fname);
oWB.Close();
oXL.Quit();
//Control button
btn.removeAttribute("disabled");
btn.setAttribute("value", "Export results to Excel");
}