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>
<TD id= "title" align= "Center" nowrap= "nowrap" class= "Td_stat" colspan= "2" >
User Information
</td>
</tr>
<tr>
<TD id= "title" align= "Center" nowrap= "nowrap" class= "Td_stat" colspan= "1" >
Name
</td>
<TD id= "title" align= "Center" nowrap= "nowrap" class= "Td_stat" colspan= "1" >
Tom
</td>
</tr>
<tr>
<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>