打印

<script type="text/javascript">
        function PageSetup_Default() {
            try {
                var Wsh = new ActiveXObject("WScript.Shell");
                var HKEY_Root, HKEY_Path, HKEY_Key;
                HKEY_Root = "HKEY_CURRENT_USER";
                HKEY_Path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
                HKEY_Key = "header";
                //设置页眉(为空)  
                Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
                HKEY_Key = "footer";
                //设置页脚,显示当前页码
                Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "&b第&p页/共&P页&b");
                HKEY_Key = "margin_bottom";
                //设置下页边距(0)  
                Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0.2");
                HKEY_Key = "margin_left";
                //设置左页边距(0)  
                Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0.2");
                HKEY_Key = "margin_right";
                //设置右页边距(0)  
                Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0.2");
                HKEY_Key = "margin_top";
                //设置上页边距(0)  
                Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0.2");
            }
            catch (e) {
                alert("不允许ActiveX控件.\n\n 解决办法:将IE安全等级设置为低(low)!");
            }
        }

        function printview() {
            //PageSetup_Default();
            //WebBrowser.printing.header = "第&p页,共&P页";
            parent.mainframe.focus();
            document.all.WebBrowser.ExecWB(7, 1);

        }
        function printSetting() {
            document.all.WebBrowser.ExecWB(8, 1);
        }
        function Printing() {
            //alert(window.parent("mainframe").name);
            if (parent.mainframe != null) {
                parent.mainframe.focus();
                parent.mainframe.print();
            }
            else {
                document.all.WebBrowser.ExecWB(6, 6);
            }
        }
        function ExportExcel() {
            try {
                //debugger;
                var curTbl = document.getElementById("ImportReport");
                var oXL = new ActiveXObject("Excel.Application");
                var oWB = oXL.Workbooks.Add();
                var oSheet = oWB.ActiveSheet;
                var sel = document.body.createTextRange();
                sel.moveToElementText(curTbl);
                sel.select();
                sel.execCommand("Copy");
                oSheet.Paste();
                oXL.Visible = true;

            }
            catch (Error) {
                alert(Error);
            }

        }

    </script>

//加载控件

    <object id="WebBrowser" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0"
        width="0">
    </object>

原文地址:https://www.cnblogs.com/lgxll/p/2660618.html