JavaScript to export table to Excel implementation ideas and code _javascript skills

Source: Internet
Author: User
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");
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.