In some small projects that are not very demanding, you can use some technologies that are not general and not new but can really implement functions well. In this way, the system is not very complicated to display and can be easily maintained.
Create a new exportPrint.html page, and the code inside is shown below, and you can export to Excel and print web pages.
The code copy is as follows:
<html>
<head>
<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>
</head>
<body>
<object classid="CLSID:8856F961-340A-11DO-A96B-00C04FD705A2" id="WebBrowser"></object>
<table align="center" cellpadding="0" cellpacing="0" style="text-align: center;">
<tr>
<td id="title" align="center" nowrap="nowrap" colspan="2">
User Information
</td>
</tr>
<tr>
<td id="title" align="center" nowrap="nowrap" colspan="1">
Name
</td>
<td id="title" align="center" nowrap="nowrap" colspan="1">
Zhang San
</td>
</tr>
<tr>
<td id="title" align="center" nowrap="nowrap" colspan="2">
<input type="button" id="export" value="export" onclick="javascript:exportToExcel();" >
<input type="button" id="print" value="print" onclick="javascript:print();" >
</td>
</tr>
</table>
</body>
</html>
<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("An error occurred! Maybe it was because the browser or the amount of data was too large!");
return;
}
appExcel = null;
oRangeRef = null;
}
}
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("An error occurred! Maybe it was because the browser or the amount of data was too large!");
return;
}
export.style.display = "";
print.style.display = "";
}
}
</script>