js WebBrowser 打印 套打

来源:互联网 发布:erp软件销售好做吗 编辑:程序博客网 时间:2024/04/29 01:33
WebBrowser 打印 套打

网页打印代码
<style media=print>
.Noprint{display:none;}
</style>

<script language="JavaScript">
function dayin(){window.print()}
function dayin1(){try{document.all.WebBrowser.ExecWB(6,6)}catch(e){alert("您的浏览器不支持此功能,需要5.5以上版本")}}
function pageSetup(){try{document.all.WebBrowser.ExecWB(8,1)}catch(e){alert("您的浏览器不支持此功能,需要5.5以上版本")}}
function preView(){try{document.all.WebBrowser.ExecWB(7,1)}catch(e){alert("您的浏览器不支持此功能,需要5.5以上版本")}}
</script>

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

<p>页面打印测试</p>

<p><span class="Noprint">测试1:
<input type=button value=打印 onclick="window.print()">
<INPUT type=button value=打印 onclick="document.execCommand('Print')">
</span>
</p>

<p class="Noprint">测试2:
<input class="Noprint" type=button value=打印 onclick="dayin()">
<input class="Noprint" type=button value=直接打印 onclick="dayin1()">
<input class="Noprint" type=button value=页面设置 onclick="pageSetup()">
<input class="Noprint" type=button value=打印预览 onclick="preView()">
</p>

<style media=print>
.Noprint{display:none;}
</style>

<script language="JavaScript">
function dayin(){window.print()}
function dayin1(){try{document.all.WebBrowser.ExecWB(6,6)}catch(e){alert("您的浏览器不支持此功能,需要5.5以上版本")}}
function pageSetup(){try{document.all.WebBrowser.ExecWB(8,1)}catch(e){alert("您的浏览器不支持此功能,需要5.5以上版本")}}
function preView(){try{document.all.WebBrowser.ExecWB(7,1)}catch(e){alert("您的浏览器不支持此功能,需要5.5以上
版本")}}
</script>

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

<p>页面打印测试</p>


<p><span class="Noprint">测试1:
<input type=button value=打印 onclick="window.print()">
<INPUT type=button value=打印 onclick="document.execCommand('Print')">
</span>
</p>

<p class="Noprint">测试2:
<input class="Noprint" type=button value=打印 onclick="dayin()">
<input class="Noprint" type=button value=直接打印 onclick="dayin1()">
<input class="Noprint" type=button value=页面设置 onclick="pageSetup()">
<input class="Noprint" type=button value=打印预览 onclick="preView()">
</p>
<style media=print>
.Noprint{display:none;}
</style>

<script language="JavaScript">
function dayin(){window.print()}
function dayin1(){try{document.all.WebBrowser.ExecWB(6,6)}catch(e){alert("您的浏览器不支持此功能,需要5.5以上版本")}}
function pageSetup(){try{document.all.WebBrowser.ExecWB(8,1)}catch(e){alert("您的浏览器不支持此功能,需要5.5以上版本")}}
function preView(){try{document.all.WebBrowser.ExecWB(7,1)}catch(e){alert("您的浏览器不支持此功能,需要5.5以上
版本")}}
</script>

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

<p>页面打印测试</p>

<p><span class="Noprint">测试1:
<input type=button value=打印 onclick="window.print()">
<INPUT type=button value=打印 onclick="document.execCommand('Print')">
</span>
</p>

<p class="Noprint">测试2:
<input class="Noprint" type=button value=打印 onclick="dayin()">
<input class="Noprint" type=button value=直接打印 onclick="dayin1()">
<input class="Noprint" type=button value=页面设置 onclick="pageSetup()">
<input class="Noprint" type=button value=打印预览 onclick="preView()">
</p>


首先在网页中添加:

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

然后就可以依次加入功能
按钮了:

<input onclick="document.all.WebBrowser.ExecWB(6,1)" type="button" value="打印"> <input onclick="document.all.WebBrowser.ExecWB(6,6)" type="button" value="直接打印">
<input onclick="document.all.WebBrowser.ExecWB(8,1)" type="button" value="页面设置">
<input onclick="document.all.WebBrowser.ExecWB(7,1)" type="button" value="打印预览"> <INPUT type="button" value="关闭窗口" onclick="javascript:window.close()">

将这两块东西放到<center class=noprint></center>就不会打印这些按钮了。当然要定义noprint了:

<style media="print">.Noprint { DISPLAY: none }</style>只要把不想打印的东西的css设置成noprint就可以了。

现在就实现了基本的web打印,需要注意的情况如下:

必须将ie的internet选项的安全设置中对于没有标记为安全的ActiveX控件进行...设置成提示或者启用,否则会报错,导致不可用。
如果在vs.net编辑环境下编辑该页面,它经常自动的给object添加多余的参数,有了这些东西,打印就会出错,所以要记得最后保存的时候删除它们。
为了简便并且达到最好的效果,我们可以在一个页面实现编辑和打印,这时候会需要很多的textbox,我们把它的css设置成.edittext
{
overflow-y:visible;
width: 100%;
border-top: none;
border-right: none;
border-bottom: none;
border-left: none;
}就可以实现在打印的时候不显示边框和multiline的textbox不显示滚动条了。

还有一些小经验就是在设置标格宽度的时候,对于A4纸张,横打用920,竖打用640,效果最好。


用CSS实现表格单元格数据自动换行或不换行
用CSS实现表格单元格数据自动换行或不换行

1、自动换行:
<style type="text/css">
.AutoNewline
{
word-break: break-all;/*必须*/
}
</style>

<table>
<tr>
<td class="AutoNewline">自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行自动换行</td>
</tr>
</table>

2、不换行:
<style type="text/css">
.NoNewline
{
word-break: keep-all;/*必须*/
}
</style>

<table>
<tr>
<td class="NoNewline">不换行不换行不换行不换行不换行不换行不换行不换行不换行不换行</td>
</tr>
</table>
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 法斗眼睛肿了怎么办 地图鱼身上有白点怎么办 人被广告牌砸了怎么办 小米手机出现繁体中文英文怎么办 雅思考试把姓名写错了怎么办 房贷的流水账假怎么办 报到证报道期限过期了怎么办 注销公司公章丢了怎么办 家里的猫太调皮怎么办 孩子纹身了我该怎么办 46天婴儿感冒了怎么办 狗病了不吃东西怎么办 幼儿急诊见风了怎么办 哺乳期乳房有硬块而且疼怎么办 哺乳期乳头破裂乳房似针扎怎么办 回奶胀痛的厉害怎么办 淡水龟的壳变软了怎么办 棕色的泰迪变白怎么办 大班教案泥石流来了怎么办 鸟类的嘴巴坏了怎么办 四川麦蚊子咬了怎么办 脸上被晒脱皮了怎么办 额头被晒脱皮了怎么办 脸黑一块白一块怎么办 小乌龟的壳软了怎么办 把田螺后面吃了怎么办 微生物生态菌群异常怎么办 怀孕初期感染了动物病毒怎么办? 金龙和银龙打架怎么办 海水缸盐度高了怎么办 洗空调洗坏了怎么办 老师是条青花鱼怎么办 吃了带鱼和南瓜怎么办 苹果平板ad忘了怎么办 小米6进海水了怎么办 小米手机掉海水里怎么办 苹果7进海水了怎么办 7p手机进海水怎么办 育海参苗出现红细菌怎么办 苹果手机掉进厕所怎么办 2个月的婴儿肺炎怎么办