首页 新闻 会员 周边

C#调用打印JS缺少对象

0
悬赏园豆:80 [已关闭问题]

从网上下了一控件,添加如下代码:<object id="factory" style="display: none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="http://localhost/ScriptX.cab#Version=5,60,0,375">
</object>

然后又下段JS:
<script language ="javascript" type = "text/C#" >
function Print() {
document.factory.printing.header = "MeadCo\'s ScriptX Changed This";
document.factory.printing.footer = "";
document.factory.printing.leftMargin = 1.0;
document.factory.printing.topMargin = 1.0;
document.factory.printing.rightMargin = 1.0;
document.factory.printing.bottomMargin = 1.0;
document.factory.printing.Print(false) // false 不弹出打印机选择框,利用默认打印机打印 true 弹出打印机选择框
document:factory.printing.PageSetup(); //打印设置
document.factory.printing.Preview(); //打印预览
}
</script>


在页面中调用如下:
<input id="btnPrintBarcode" onclick="printit();" style="width: 85px"
type="button" value="打印报表" />

为什么运行后一点击打印报表就会弹出“出现了运行时错误,缺少对象”,小女不才,不知道C#怎么做打印,就从网上下一JS,然后调用,不过不知道还差点什么啊?

木子林的主页 木子林 | 初学一级 | 园豆:20
提问于:2008-12-29 14:08
< >
分享
其他回答(1)
0

首先你这个js应该是在调用一个activeX空间,

codebase="http://localhost/ScriptX.cab#Version=5,60,0,375">
你的这个地方要保留原来的写法,就是不要localhost,除非你机器上的相应请求可以获得或注册了这个组件。

此外,不知道你这个打印想怎么做,似乎是想直接打印页面,那么你可以使用

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <link href="css/print.css" rel="stylesheet" type="text/css" />
    <title class="hidenElement">网络打印</title>
    <script language="javascript" type="text/javascript">  
        function doPrintSetup(){
            //打印设置
            var wbObj = document.getElementById("wb");  
            wbObj.ExecWB(8,1);
        }  
        function doPrintPreview(){
            //打印预览
            var wbObj = document.getElementById("wb");  
            wbObj.ExecWB(7,1);
        }  
        function doPrint(){  
            //直接打印
           //var wbObj = document.getElementById("wb");  
           //wbObj.ExecWB(6,6);
           window.print();
        }
   </script>
</head>
<body oncontextmenu="javascript:return false;" ondragstart="javascript:return false;" onselectstart ="javascript:return false;"
            onselect="javascript:document.selection.empty();" oncopy="javascript:document.selection.empty();"
            onbeforecopy="javascript:return false;" onmouseup="javascript:document.selection.empty();">
    <form id="_form" runat="server">
    <div style="display:none;">
        <%--<object id="wb" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>--%>
    </div>
    <div class="hidenElement">
        <table width="100%">
            <tr>
                <td align="left">
                    <%--<input id="bntPrintSetup" type="button" value="打印设置" onclick="doPrintSetup();" />
                    <input id="btnPrintPreview" type="button" value="打印预览" onclick="doPrintPreview();" />--%>
                    <input id="btnPrint" type="button" value="点击此按钮开始打印水平线以下部分" onclick="doPrint();" />
                </td> 
            </tr>
        </table>
     </div>
    <hr class="hidenElement" />    </form>
</body>
</html>
在css通过

@media print
{
 .hidenElement{
  display:none;
 }
}

来控制是否打印输出,凡是class=hidenElement元素就不打印了

GUO Xingwang | 园豆:3885 (老鸟四级) | 2008-12-29 14:27
0

上面的回答比较中肯

lz你用的是很有名的打印ActiveX控件,叫ScriptX,你去找找这个控件吧,可以直接设置打印效果(就像你代码里写的)

而楼上的代码不能做到,且只能在IE中调用wbObj.ExecWB

没办法,基于Web的打印就是比较烦的,如果要求比较多,最好还是用ActiveX吧,ScriptX不错,lz去搜搜吧

LanceZhang | 园豆:857 (小虾三级) | 2008-12-30 16:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册