Copy Code code as follows:
function Copytoexcel (tableid) {
Control button
var btn = document.getElementById ("copy");
Btn.setattribute ("Disabled", "true");
Btn.setattribute ("value", "process ...");
var curtbl = document.getElementById (TableID);
try {
var oXL = new ActiveXObject ("Excel.Application");
}
catch (e) {//ie security level is not set an error will occur (Automation server cannot create object)
/*
If it is Scripting.FileSystemObject (FSO text file read and write) is closed, open the FSO function, in the "Run" in the implementation of Regsvr32 scrrun.dll can be
*/
Alert ("Unable to start excel!\n\n if you are sure that Excel is already installed on your computer," + "adjust the security level of IE.) \ n specific action: \ n \ nthe "+" tool →internet option → security → custom level → initialize and script ActiveX without marking for security → 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");
}