zoukankan
html css js c++ java
ASP.NET 页面打印与预览
第一种是所见即所得的:
所见即所得
<
html
>
<
head
>
<
title
>
ASP.NET 打印 - 所见即所得
</
title
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=gb2312"
>
<
script
language
="javascript"
>
function
preview()
{
bdhtml
=
window.document.body.innerHTML;
sprnstr
=
"
<!--startprint-->
"
;
eprnstr
=
"
<!--endprint-->
"
;
prnhtml
=
bdhtml.substr(bdhtml.indexOf(sprnstr)
+
17
);
prnhtml
=
prnhtml.substring(
0
,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML
=
prnhtml;
window.print();
//
prnform.htext.value=prnhtml;
//
prnform.submit();
//
alert(prnhtml);
}
</
script
>
</
head
>
<
body
bgcolor
="#FFFFFF"
text
="#000000"
>
辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣
<
center
>
本部分以上不被打印
</
center
>
<!--
startprint
-->
<
table
width
="84%"
align
="center"
bgcolor
="#0000FF"
cellpadding
="2"
cellspacing
="1"
>
<
tr
bgcolor
="#6699FF"
>
<
td
>
<
div
align
="center"
>
标题一
</
div
>
</
td
>
<
td
>
<
div
align
="center"
>
标题二
</
div
>
</
td
>
<
td
>
<
div
align
="center"
>
标题三
</
div
>
</
td
>
<
td
>
<
div
align
="center"
>
标题四
</
div
>
</
td
>
<
td
>
<
div
align
="center"
>
标题五
</
div
>
</
td
>
</
tr
>
<
tr
bgcolor
="#6699FF"
>
<
td
>
</
td
>
<
td
>
</
td
>
<
td
>
</
td
>
<
td
>
</
td
>
<
td
>
</
td
>
</
tr
>
</
table
>
<!--
endprint
-->
<
center
>
本部分以下不被打印
</
center
>
辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣辣
<
div
align
="center"
>
<
input
type
="button"
name
="print"
value
="预览并打印"
onclick
="preview()"
>
</
div
>
<
style
>
@media print
{
}
{
.Noprn {display
:
none
;
}
}
</
style
>
<
p
class
="Noprn"
>
不打印
</
p
>
<
table
id
=datagrid
><
tr
><
td
>
打印
</
td
></
tr
></
table
>
<
input
class
=Noprn
type
=button
onclick
="window.print()"
value
="print"
>
</
body
>
</
html
>
第二种是对页面样式进行解析后的
Print.js
function
doPage()
{
layLoading.style.display
=
"
none
"
;
//
同上
}
//
设置网页打印的页眉页脚为空
function
PageSetup_Null()
{
try
{
var
Wsh
=
new
ActiveXObject(
"
WScript.Shell
"
);
HKEY_Key
=
"
header
"
;
Wsh.RegWrite(HKEY_Root
+
HKEY_Path
+
HKEY_Key,
""
);
HKEY_Key
=
"
footer
"
;
Wsh.RegWrite(HKEY_Root
+
HKEY_Path
+
HKEY_Key,
""
);
}
catch
(e)
{}
}
//
设置网页打印的页眉页脚为默认值
function
PageSetup_Default()
{
try
{
var
Wsh
=
new
ActiveXObject(
"
WScript.Shell
"
);
HKEY_Key
=
"
header
"
;
Wsh.RegWrite(HKEY_Root
+
HKEY_Path
+
HKEY_Key,
"
&w&b页码,&p/&P
"
);
HKEY_Key
=
"
footer
"
;
Wsh.RegWrite(HKEY_Root
+
HKEY_Path
+
HKEY_Key,
"
&u&b&d
"
);
}
catch
(e)
{}
}
/**/
/*
*预览函数
*controlsList 要隐藏的控件
*doType 页面页脚类型 0 设置为空,1 设置为默认
*/
function
printpr(controlsList,doType)
{
if
(doType
==
'
0
'
)
{
PageSetup_Null();
}
else
{
PageSetup_Default();
}
var
control
=
controlsList.split(
"
,
"
);
for
(i
=
0
;i
<
control.length;i
++
)
{
//
隐藏控件
document.getElementById(control[i]).style.display
=
"
none
"
;
}
var
OLECMDID
=
7
;
var
PROMPT
=
1
;
var
WebBrowser
=
'
<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>
'
;
document.body.insertAdjacentHTML(
'
beforeEnd
'
, WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML
=
""
;
for
(i
=
0
;i
<
control.length;i
++
)
{
//
打印之后将该元素显示出来
document.getElementById(control[i]).style.display
=
""
;
}
window.location.reload();
//
刷新窗口
}
/**/
/*
*预览函数
*controlsList 要隐藏的控件(用逗号连接)
*doType 页面页脚类型 0 设置为空,1 设置为默认
*/
function
printTure(controlsList,doType)
//
打印函数
{
if
(doType
==
'
0
'
)
{
PageSetup_Null();
}
else
{
PageSetup_Default();
}
var
control
=
controlsList.split(
"
,
"
);
for
(i
=
0
;i
<
control.length;i
++
)
{
//
隐藏控件
document.getElementById(control[i]).style.display
=
"
none
"
;
}
window.print();
for
(i
=
0
;i
<
control.length;i
++
)
{
document.getElementById(control[i]).style.display
=
""
;
}
window.location.reload();
}
打印调用
<
div
style
="text-align: right"
>
<
input
type
="button"
name
="btn"
value
="打印"
onclick
="printTure('btn,show','0')"
/>
<
input
type
="button"
name
="show"
value
="预览"
onclick
="printpr('btn,show','0')"
/>
</
div
>
查看全文
相关阅读:
快速入门系列--MVC--05行为
2015链家网面试记录
快速入门系列--MVC--04模型
django 添加动态表格的方法
git clone
postgresql数据库实用操作
django 实战
Android手机分辨率基础知识(DPI,DIP计算)
Android中xml设置Animation动画效果详解
Unable to execute dex: Multiple dex files define Lcom/gl
原文地址:https://www.cnblogs.com/luluping/p/1499558.html
最新文章
iptables
分享一个 jmeter ant的build.xml
网上搜索到的 比较好的mysql查询语句练习题
如何通过jmeter使用beanshell进行关联
Jmeter之Bean shell学习(一)
一个优秀的测试人员所具备的素质 ------来自测试百晓生视频
Appium环境搭建(python)
使用Jmeter进行http接口测试 ---------成都杀手
python version 2.7 required,which was not found in the registry
【Cocos2d-Js基础教学(5)资源打包工具的使用及资源的异步加载处理】
热门文章
基于kbengine 0.4.20
基于kbengine 0.4.20 解读
游戏服务端架构 介绍
分类测试
在 CentOS7 上部署 zookeeper 服务
在 CentOS7 之部署 Redis3
在 CentOS7 上安装 MongoDB
在 CentOS7 上安装 MySQL5.7
在 CentOS7 上安装 Tomcat9
在CentOS7上安装JDK1.8
Copyright © 2011-2022 走看看