使用WebBrowser控制項
一、WebBrowser控制項(通過Style的設定可以實現部分列印)
<object ID='WebBrowser' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>
二、WebBrowder控制項的方法
1、列印
WebBrowser1.ExecWB(6,1);
2、列印設定
WebBrowser1.ExecWB(8,1);
3、預覽列印
WebBrowser1.ExecWB(7,1);
三、列印頁首頁尾設定
var hkey_root,hkey_path,hkey_key
hkey_root="HKEY_CURRENT_USER"
hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"
1、清空頁首頁尾
try{
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key="header"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
hkey_key="footer"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
}catch(e){}
2、設定頁首頁尾 www.2cto.com
try{
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key="header"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&w&b頁碼,&p/&P")
hkey_key="footer"
RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"&u&b&d")
}catch(e){}
四、頁面列印
由於列印是會把整個頁面都列印出來的,但如果只需要列印資料表格,這時我們就把不想列印的部份隱藏起來
1、
//把指定id以外的層統統隱藏
function setdivhidden(id){
var divs=document.getElementsByTagName("DIV");
for(var i=0;i<divs.length;i++)
{
if(divs.item(i).id!=id)
divs.item(i).style.display="none";
}
}
2、
// 列印版面設定
function printsetup(){
WebBrowser.execwb(8,1);
}
3、// 列印頁面預覽
function printpreview(){
WebBrowser.execwb(7,1);
}
4、列印
function printit() {
if (confirm('確定列印嗎?'))
WebBrowser.execwb(6,1)
}
5、HTML頁面元素
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
<input type=button name=button_print value="列印" class="noprint" onclick="javascript:printit()">
<input type=button name=button_setup value=”列印版面設定” class="noprint" onclick="javascript:printsetup();">
<input type=button name=button_show value="預覽列印" class="noprint" onclick="javascript:printpreview();">
摘自Core_Star的專欄