IE browsers use JS to export Web pages to Excel and print _javascript tips

Source: Internet
Author: User

In small projects that are not very high in requirements, you can implement these features with technologies that are not generic and are not new but can actually implement functionality well. This system is not shown to be complex and can be easily maintained.
Create a new exportprint.html page with the code shown below to enable you to export to Excel and print your Web pages.

Copy Code code as follows:

<title>ie Browser uses JS technology to export to Excel and print </title>
<style>
. table_stat {
border-right:0px;
border-bottom:0px;
border-left:1px solid #819BD8;
border-top:1px solid #819BD8;
}
. td_stat {
border-right:1px solid #819BD8;
border-bottom:1px solid #819BD8;
}
</style>
<body>
<object classid= "CLSID:8856F961-340A-11DO-A96B-00C04FD705A2" height= "0" id= "WebBrowser" width= "0" ></ Object>
<table width= "100%" align= "center" border= "0" cellpadding= "0" cellspacing= "0" style= "text-align:center;" class= " Table_stat ">
<tr>
&LT;TD id= "title" align= "Center" nowrap= "nowrap" class= "Td_stat" colspan= "2" >
User Information
</td>
</tr>
<tr>
&LT;TD id= "title" align= "Center" nowrap= "nowrap" class= "Td_stat" colspan= "1" >
Name
</td>
&LT;TD id= "title" align= "Center" nowrap= "nowrap" class= "Td_stat" colspan= "1" >
Tom
</td>
</tr>

<tr>
&LT;TD id= "title" align= "Center" nowrap= "nowrap" class= "Td_stat" colspan= "2" >
<input type= "button" id= "Export" value= "onclick=" Javascript:exporttoexcel (); ">
<input type= "button" id= "print" value= "onclick=" Javascript:print (); ">
</td>
</tr>
</table>
</body>

<script type= "Text/javascript" >
Export to Excel
function exportToExcel () {
if (document.getElementById ("title")) {
try {
var orangeref = Document.body.createTextRange ();
Orangeref.execcommand ("Copy");
var appexcel = new ActiveXObject ("Excel.Application");
Appexcel.visible = true;
APPEXCEL.WORKBOOKS.ADD (). Worksheets.item (1). Paste ();
catch (e) {
Alert ("Wrong!") Maybe the browser or the amount of data is too big! ");
Return
}
Appexcel = null;
Orangeref = null;
}
}

Print
function print () {
if (document.getElementById ("title")) {
var export = document.getElementById ("Export");
var print = document.getElementById ("print");
try {
Export.style.display = "None";
Print.style.display = "None";
Document.all.WebBrowser.ExecWB (6,1);
catch (e) {
Alert ("Wrong!") Maybe the browser or the amount of data is too big! ");
Return
}
Export.style.display = "";
Print.style.display = "";
}
}
</script>

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.