自定义打印
来源:互联网 发布:手机淘宝网首页官网 编辑:程序博客网 时间:2024/05/29 04:54
1 第一种方法:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPrint.aspx.cs" Inherits="TestPrint" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 300px;
}
</style>
<SCRIPT language=javascript>
function printpr() //预览函数
{
document.all("qingkongyema").click(); //打印之前去掉页眉,页脚
document.all("dayinDiv").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 = "";
document.all("dayinDiv").style.display = ""; //打印之后将该元素显示出来(显示出“打印”和“打印预览”两个按钮,方便别人下次打印)
}
function printTure() //打印函数
{
document.all('qingkongyema').click(); //同上
document.all("dayinDiv").style.display = "none"; //同上
window.print();
document.all("dayinDiv").style.display = "";
}
function doPage() {
layLoading.style.display = "none"; //同上
}
</SCRIPT>
<script language="JavaScript">
var hkey_root, hkey_path, hkey_key
hkey_root = "HKEY_CURRENT_USER"
hkey_path = "//Software//Microsoft//Internet Explorer//PageSetup//"
//设置网页打印的页眉页脚为空
function pagesetup_null() {
try {
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key = "header"
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "")
hkey_key = "footer"
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "")
} catch (e) { }
}
//设置网页打印的页眉页脚为默认值
function pagesetup_default() {
try {
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key = "header"
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&w&b页码,&p/&P")
hkey_key = "footer"
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "&u&b&d")
} catch (e) { }
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<br />
<br />
<br />
<DIV align=center>
<table class="style1">
<tr>
<td>
商品名:</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
数量:</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
总价:</td>
<td>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
操作员:</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" ontextchanged="TextBox2_TextChanged"></asp:TextBox>
</td>
</tr>
</table>
</DIV>
<DIV align="center" id="dayinDiv" name="dayinDiv"><input type="button" class="tab" value="打印" onclick="printTure();">
<input type="button" class="tab" value="打印预览" onclick="printpr();">
<input type="hidden" name="qingkongyema" id="qingkongyema" class="tab" value="清空页码" onclick="pagesetup_null()">
<input type="hidden" class="tab" value="恢复页码" onclick="pagesetup_default()">
</DIV>
</div>
</form>
</body>
</html>
第二种方法:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Print.aspx.cs" Inherits="Print" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language=javascript>
function printsetup() {
// 打印页面设置
wb.execwb(8, 1);
}
function printpreview() {
// 打印页面预览
wb.execwb(7, 1);
}
function printit() {
if (confirm('确定打印吗?')) {
wb.ExecWB(6, 1)
//wb.execwb(1,1)//打开
//wb.ExecWB(2,1);//关闭现在所有的IE窗口,并打开一个新窗口
//wb.ExecWB(4,1)//;保存网页
//wb.ExecWB(6,1)//打印
//wb.ExecWB(7,1)//打印预览
//wb.ExecWB(8,1)//打印页面设置
//wb.ExecWB(10,1)//查看页面属性
//wb.ExecWB(15,1)//好像是撤销,有待确认
//wb.ExecWB(17,1)//全选
//wb.ExecWB(22,1)//刷新
//wb.ExecWB(45,1)//关闭窗体无提示
}
}
</script>
<style media="print">
.noprint {display:none;}
</style>
<style type="text/css">
.style1
{
width: 300px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<OBJECT id="wb" height="0" width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</OBJECT>
<div class="noprint">
</div>
<DIV align=center>
<table class="style1">
<tr>
<td>
商品名:</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
单价:</td>
<td>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
数量:</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
总价:</td>
<td>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
操作员:</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>
</td>
</tr>
</table>
</DIV>
<div class="noprint" align="center"> <input onclick="document.getElementById('wb').ExecWB(6,6)" type="button" value="直接打印">
<input onclick="document.getElementById('wb').ExecWB(8,1)" type="button" value="页面设置">
<input onclick="document.getElementById('wb').ExecWB(7,1)" type="button" value="打印预览">
</div>
</form>
</body>
</html>
第三种分页打印:
<html>
<head>
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<title>***上海市眼病防治中心病人结帐费用报表***</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print 这个属性可以在打印时有效-->
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<style>
body,td,th
{
font-size: 12px;
}
.tdp
{
border-bottom: 1 solid #000000;
border-left: 1 solid #000000;
border-right: 0 solid #ffffff;
border-top: 0 solid #ffffff;
}
.tabp
{
border-color: #000000;
border-collapse:collapse;
}
.NOPRINT {
font-family: "宋体";
font-size: 12px;
}
</style>
</head>
<body >
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0 VIEWASTEXT>
</OBJECT>
<input type=button value=打印 onclick="document.all.WebBrowser.ExecWB(6,1)" class="NOPRINT">
<input type=button value=直接打印 onclick="document.all.WebBrowser.ExecWB(6,6)" class="NOPRINT">
<input type=button value=页面设置 onclick="document.all.WebBrowser.ExecWB(8,1)" class="NOPRINT">
<input type=button value=打印预览 onclick="document.all.WebBrowser.ExecWB(7,1)" class="NOPRINT">
<br/>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr align="center">
<td colspan="5"><font size="3">上海市眼病防治中心病人结帐费用报表(A) </font></td>
</tr>
<tr>
<td>汇总人次 5</td>
<td>费用合计 15853.12</td>
<td>统计日期 </td>
<td>制表人 023</td>
<td>制表日期:2004-05-13</td>
</tr>
</table>
<table width="90%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#000000" class="tabp">
<tr>
<td >姓名</td>
<td >住院号</td>
<td >科室</td>
<td >结帐日期</td>
<td >出院日期</td>
<td >费用合计</td>
<td >医保交易费用</td>
<td >分类给付费用</td>
<td >非医保交易费</td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
</tr>
<tr>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
<td > </td>
</tr>
</table>
<hr align="center" width="90%" size="1" noshade class="NOPRINT" >
<!--分页-->
<div class="PageNext"></div>
<table width="90%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#000000" class="tabp">
<tr>
<td >第2页</td>
</tr>
<tr>
<td >看到分页了吧</td>
</tr>
<tr>
<td > </td>
</tr>
<tr>
<td > </td>
</tr>
<tr>
<td ><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" >这样的报表
对一般的要求就够了。</td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
- 自定义打印
- 自定义Web打印内容
- eprint自定义打印工具
- 打印自定义纸张大小
- 打印自定义纸张大小
- 页面打印自定义设置
- 自定义打印内容参数设置
- VC++自定义纸张打印
- 打印自定义纸张大小
- sap自定义打印格式
- 打印自定义菱形
- 自定义打印日志
- 自定义菱形打印
- Devexpress 自定义打印
- C# 自定义打印
- 自定义Android Log打印
- NJLog 自定义日志打印
- MFC自定义打印功能
- 分析elf文件的利器(常用命令)
- OpenCV 2.4.6 + VS2010 + win7 环境配置
- 聚簇索引与非聚簇索引的区别以及SQL Server查询优化技术
- 藏文文本在MFC编辑框控件中显示不完整,下部被截断了一部分原因分析
- step by step 配置mysql复制
- 自定义打印
- 不允许一个用户使用一个以上用户名与一个服务器或共享资源的多重连接。中断与此服务器的所有连接
- Android LCD(一):LCD基本原理篇
- Java中的transient关键字
- __declspec(dllimport)和__declspec(dllexport)
- 无法找到“XXX.exe”的调试信息,或者调试信息不匹配。。
- toj1469 Wooden Sticks
- 关于如何按位强制转化,如float与int之间按位转化
- B树和B树的实现 B-Tree