[ASP.NET] 列印所顯示的網頁內容

  • 6548
  • 0

摘要:[ASP.NET] 列印所顯示的網頁內容

最近剛好小弟比較有空,因此做個小紀錄防止忘記

之前遇到USER需要在web介面下列印網頁內容

小弟不才...多多指教

<<方法1 -- 透過WebBrowserj物件來列印>>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>未命名頁面</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <br />
        <object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" width="0"></object>
        <input type="button" value="列印" onclick="document.all.WebBrowser.ExecWB(6,1)" id="Button2" name="Button2" />
        <input type="button" value="直接列印" onclick="document.all.WebBrowser.ExecWB(6,6)" id="Button3" name="Button3" />
        <input type="button" value="頁面設置" onclick="document.all.WebBrowser.ExecWB(8,1)" id="Button4" name="Button4" />
        <input type="button" value="列印預覽" onclick="document.all.WebBrowser.ExecWB(7,1)" id="Button5" name="Button5" />
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    </div>
    </form>
</body>
</html>

 

 

 

// 附上常用指令
document.all.WebBrowser.ExecWB(1,1) //打開
document.all.WebBrowser.ExecWB(2,1) //關閉全部
document.all.WebBrowser.ExecWB(4,1) //另存為
document.all.WebBrowser.ExecWB(6,1) //列印
document.all.WebBrowser.ExecWB(6,6) //直接列印
document.all.WebBrowser.ExecWB(7,1) //預覽列印
document.all.WebBrowser.ExecWB(8,1) //頁面設置
document.all.WebBrowser.ExecWB(10,1) //屬性
document.all.WebBrowser.ExecWB(17,1) //全選
document.all.WebBrowser.ExecWB(22,1) //刷新
document.all.WebBrowser.ExecWB(45,1) //關閉

 

<<方法2 -- 透過JavaScript來列印>>

window.print();

 

 






Y2J's Life:http://kimenyeh.blogspot.tw/