`

打印跟换行的一些参考内容(来自互联网)

阅读更多
网页打印代码
<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="打印预览">&nbsp;<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>



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics