在一些要求不是很高的小項(xiàng)目中,可以使用一些雖不是通用且不是新技術(shù)但是確實(shí)可以很好實(shí)現(xiàn)功能的技術(shù)來實(shí)現(xiàn)這些功能。這樣系統(tǒng)不是顯示的很復(fù)雜,且可以方便維護(hù)。
新建一個exportPrint.html頁面,里面的代碼如下所示,就可以實(shí)現(xiàn)導(dǎo)出到Excel和打印網(wǎng)頁。
復(fù)制代碼 代碼如下:
<html>
<head>
<title>IE瀏覽器使用JS技術(shù)導(dǎo)出到Excel和打印</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"></object>
<table cellpadding="0" cellspacing="0">
<tr>
<td nowrap="nowrap" colspan="2">
用戶信息
</td>
</tr>
<tr>
<td nowrap="nowrap" colspan="1">
姓名
</td>
<td nowrap="nowrap" colspan="1">
張三
</td>
</tr>
<tr>
<td nowrap="nowrap" colspan="2">
<input type="button" value="導(dǎo)出" >
<input type="button" value="打印" >
</td>
</tr>
</table>
</body>
</html>
<script type="text/javaScript">
//導(dǎo)出到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("出錯啦!可能是瀏覽器或者是數(shù)據(jù)量太大咯哦!");
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("出錯啦!可能是瀏覽器或者是數(shù)據(jù)量太大咯哦!");
return;
}
export.style.display = "";
print.style.display = "";
}
}
</script>
新聞熱點(diǎn)
疑難解答
圖片精選