有关B/S打印的千古难题! 我是做商务软件,利用就是WEB的方便性,我拒绝使用客户端控件,如果用控件的话,我还不如用C/S结构实现呢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 微软明确说明,b/s下是不能报表打印的(html打印除外),转换成pdf文档再打印是b/s常用的方法:try{ string sql=getSql(start.Text,end.Text); //System.Data.OleDb.OleDbConnection conn=new System.Data.OleDb.OleDbConnection("PROVIDER=OraOLEDB.Oracle;DATA SOURCE=new;USER ID=fscrmsa;PASSWORD=s;PLSQLRSet=1");string ConnectionString=fscrm.include.db.ConnectionString;System.Data.OleDb.OleDbConnection conn=new //产生一个相关报表对象。System.Data.OleDb.OleDbConnection(ConnectionString);fscrm.psales.rpt.dhbb_1 oRpt = new fscrm.psales.rpt.dhbb_1(); System.Data.OleDb.OleDbDataAdapter comm=new System.Data.OleDb.OleDbDataAdapter(sql,conn);DataSet ds = new DataSet();comm.Fill(ds,"table");oRpt.SetDataSource(ds.Tables["table"]); ExportOptions crExportOptions=new ExportOptions();DiskFileDestinationOptions crDiskFileDestinationOptions = new DiskFileDestinationOptions();string path=Request.ServerVariables["APPL_PHYSICAL_PATH"];path=path.Replace("\\","\\\\");string Fname1="zxh"+System.DateTime.Now.Year+System.DateTime.Now.Month+System.DateTime.Now.Day+ System.DateTime.Now.Hour+System.DateTime.Now.Minute+System.DateTime.Now.Second+System.DateTime.Now.Millisecond+".pdf";string Fname=path+"temp\\"+Fname1;crDiskFileDestinationOptions.DiskFileName = Fname;oRpt.ExportOptions.DestinationOptions=crDiskFileDestinationOptions;oRpt.ExportOptions.ExportDestinationType=ExportDestinationType.DiskFile; oRpt.ExportOptions.ExportFormatType=ExportFormatType.PortableDocFormat;oRpt.Export();string aa="window.open('/temp/"+Fname1+"')";Response.Write("<script language='JavaScript'>"+"\n");Response.Write(aa);Response.Write("</script>"+"\n");}catch{return;} to blade_780515(流离在全国各地的狗):您好,是我表达有误,我所谓的报表打印,实际上就是打印HTML文件,只不过打印出来的形式是报表样式。 关注ing顺便问一下,c/s是client/server结构,而b/s是什么呢? 那你可以先向你的html文件输出报表样式;再打印该html文件,window.print() 你可以先向你的html文件输出报表样式;再打印该html文件,window.print() To ameng_2002(wader) :这位大哥回答的可真及时,小弟手头也一些有这方面的资料,只是不够系统,还没有融汇贯通。只是希望有人能有现成的好的方法,可供参考和交流! 可以用其他开发工具把打印控件做成ocx控件,然后供BS使用 开发B/S结构的应用程序最头疼的问题可能就是报表打印了,由于只能采用浏览器来作为用户界面进行交互,所以不能精确控制客户端的打印机。而很多B/S结构的应用程序常常需要完成非常复杂的报表打印任务。而靠IE自带的页面打印功能一般不能满足需要。采用Crystal Report是一种大型报表系统常用和推荐的解决方案,但是如果我们只需要进行一些小规模的报表打印的话,Crystal Report则显得庞大麻烦了一点,可定制性也不太好,它的打印实际上也是利用了IE的打印功能,也不能精确控制打印效果,而且需要您对它进行注册。技术选择由于.NET framework的winform可以直接嵌入到网页中,这么做并不代表.NET winform是唯一的选择,其实您可以采用任何客户端代替它,例如Java Applet或者ActiveX,甚至是一个普通的应用程序都能行。不允许直接连接到数据库,因此只能采用XML文件进行中间数据交换格式,通过普通WEB服务器的默认80端口进行数据传输。当然,web service也许能算是一种,但是它采用的是SOAP传输数据.采用.NET编写的受控组件,优点在于:1. 它不需要进行客户端注册。相对于ActiveX的一个大优点。2. 比ActiveX安全性高。在.NET Common Language Runtime的控制之下运行3. 编写方便。我喜欢C#和Visual Studio .NET。4. 有很强大的打印控制功能。利用.NET framework类库。5. 直接支持XML技术。6. 和IE兼容性高。同为Microsoft公司产品。 最近可能会做一个打印控件,有机会我们可以交流QQ:35839994,MSN:[email protected] To ZHANG9652:谢谢大哥的支持! 在中国DotNet俱乐部看到的一个帖子,不知对你有没有帮助,内容如下:一、前言ASP在电子商务上应用广泛,报表的处理又有一些麻烦。本文介绍了在ASP中利用本人写的Report Server Page脚本解释器实现报表的显示、打印。二、准备工作(1)安装Visual Reprort Design软件Visual Report Design是本人写的一个免费的报表设计器,程序的发行只需要安装一个60K的控件即可。想要的网友可以到http://go.163.com/reportpro/下载 (2)设计报表通过Visual Report Design 的可视化界面可以生成报表的脚本:mxb.rsp。三、实现报表的打印、显示下面是调用的文档:printmx.asp<%Option Explicit%><%dim ReportName,retdim ReportAtldim nameset ReportAtl=Session("ReportAtl")ReportName=Server.MapPath("mxb.rsp")ret=reportatl.XMLToVBS(ReportName)if ret=-1 thenresponse.write reportatl.ErrorMsgresponse.endend ifReportName=Server.MapPath("mxb.vbs")ret=reportatl.DoScript(ReportName)if ret=-1 thenresponse.write reportatl.ErrorMsgset ReportAtl=nothingresponse.endend ifset ReportAtl=nothing%><html><OBJECT id=reportatl classid="clsid:D3F064E5-F4C0-4C52-9E7F-263D96B7EA11" codebase="Report.cab#version=1,0,0,1"></OBJECT><script language=vbscript>dim retret=reportatl.DoPrintReport("mxb.zcg")if ret=-1 thenmsgbox reportatl.ErrorMsgend if</script></html> 用Visual Report Design 产生的报表脚本mxb.rsp:<?xml version='1.0' encoding='GB2312' ?><!DOCTYPE report SYSTEM 'print_report.dtd' ><report name='报表'><report_script>dim rs,con,sql,lshdim tempset con =CreateObject("ADODB.Connection")con.ConnectionString = "DBQ=c:\report\demo\asp\report.mdb;DRIVER={Microsoft Access Driver (*.mdb)};"con.openSet rs =CreateObject("ADODB.Recordset")sql="SELECT * FROM cj,student where cj.id=student.id "rs.open sql,con,1,3</report_script><report_head height='12'><text name='vfptext' top='4' left='76' width='26' height='5' font_name='宋体' font_size='14' font_weight='700' font_italic='0' font_underline='0' >成绩明细表</text></report_head><page_head height='6'><line name='vfpline' top='0' left='9' width='178' height='0' weight='131072'></line><line name='vfpline' top='6' left='9' width='178' height='0' weight='131072'></line><text name='vfptext' top='2' left='18' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >姓名</text><text name='vfptext' top='2' left='46' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >语文</text><text name='vfptext' top='2' left='72' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >数学</text><text name='vfptext' top='2' left='99' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >英语</text><text name='vfptext' top='2' left='162' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >合计</text><text name='vfptext' top='2' left='130' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >平均</text></page_head><page_body height='8'><text name='vfptext' top='2' left='15' width='25' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> Report.Write cstr(rs("xm"))</report_script></text><text name='vfptext' top='2' left='45' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> Report.Write cstr(rs("yw"))</report_script></text><text name='vfptext' top='2' left='71' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> Report.Write cstr(rs("sx"))</report_script></text><text name='vfptext' top='2' left='98' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> Report.Write cstr(rs("yy"))</report_script></text><text name='vfptext' top='2' left='130' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> Report.Write cstr((rs("yw")+rs("sx")+rs("yy"))/3)</report_script></text><text name='vfptext' top='2' left='162' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> Report.Write cstr(rs("yw")+rs("sx")+rs("yy"))</report_script></text></page_body><page_foot height='7'><text name='vfptext' top='2' left='12' width='13' height='3' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> report.write "打印日期:"+formatdatetime(date(),1)</report_script></text><text name='vfptext' top='2' left='137' width='50' height='3' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >共%Pages%页,第%Page%页</text><line name='vfpline' top='0' left='8' width='178' height='0' weight='131072'></line></page_foot><report_script>do while not rs.eofpage_body()rs.movenextlooprs.closeset rs=nothingcon.closeset con=nothing</report_script></report> 继续< %@ Language=VBScript %> < %Option ExplicitDim strSubmit 'Form中用来保存提交按钮的值Dim strPrinterPath 'Form中保存网络打印机路径的值Dim strUsername 'Form中用户名的值Dim strPassword 'Form中密码的值Dim strMessage 'Form打印内容的值Dim objFS 'VBScript中的文件系统对象Dim objWSHNet 'WSH中的网络对象Dim objPrinter '打印对象strSubmit = Request.Form("Submit")%> < HTML> < HEAD> < META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> < /HEAD> < BODY> < %If strSubmit = "" Then%> 注意的是:由于这是演示,其中有关NT的帐号和密码都是使用了不加密的手段在ASP中传递的真正的运用中应该对该登录过程进行安全处理。< FORM action="ASPPrint.asp" method=POST id=form name=form> < TABLE WIDTH=100% ALIGN=center BORDER=0 CELLSPACING=1 CELLPADDING=1> < TR> < TD ALIGN=right NOWRAP> 网络打印机路径:< /TD> < TD ALIGN=left NOWRAP> < INPUT type="text" id=printerpath name=printerpath value="< Domain > < Printer > "> < /TD> < /TR> < TR> < TD ALIGN=right NOWRAP> 登录帐号:< /TD> < TD ALIGN=left NOWRAP> < INPUT type="text" id=username name=username value="< % = strUsername %> "> < /TD> < /TR> < TR> < TD ALIGN=right NOWRAP> 登录口令:< /TD> < TD ALIGN=left NOWRAP> < INPUT type="password" id=password name=password> < /TD> < /TR> < TR> < TD ALIGN=right NOWRAP> 请输入你想打印的文字:< /TD> < TD ALIGN=left NOWRAP> < TEXTAREA rows=2 cols=20 id=message name=message> < /TEXTAREA> < /TD> < /TR> < TR> < TD ALIGN=right NOWRAP> < /TD> < TD ALIGN=left NOWRAP> < INPUT type="submit" value="Submit" id=submit name=submit> < /TD> < /TR> < /TABLE> < /FORM> 当以上信息被提交后,就可以按照下面的代码进行打印了。< %Else' 从form中取得响应信息。strPrinterPath = Request.Form("printerpath")strUsername = Request.Form("username")strPassword = Request.Form("password")strMessage = Request.Form("message")We will now use the VBScript FileSystemObject object and the WSH Network object. The Network object willgive us the methods we need to open a printer connection, and the FileSystemObject will allow us to stream ouroutput to the printer. We create these objects in the following code example: Set objFS = CreateObject("Scripting.FileSystemObject")Set objWSHNet = CreateObject("WScript.Network")' 使用WSH连接网络打印机objWSHNet.AddPrinterConnection "LPT1", strPrinterPath, False, strUsername, strPassword' 使用文件系统对象将打印设备作为一个文件使用Set objPrinter = objFS.CreateTextFile("LPT1:", True)' 给打印设备送出文本objPrinter.Write(strMessage)'关闭打印设备对象并进行错误陷阱处理On Error Resume NextobjPrinter.Close' 如果发生错误,关闭打印连接,并输出错误信息If Err ThenResponse.Write ("Error # " & CStr(Err.Number) & " " & Err.Description)Err.Clear Else' 操作成功,输出确认信息Response.Write("< CENTER> ")Response.Write("< TABLE WIDTH=100% ALIGN=center BORDER=0 CELLSPACING=1 CELLPADDING=1> ")Response.Write("< TR> < TD ALIGN=RIGHT> < B> 打印消息送出:< /B> < /TD> ")Response.Write("< TD ALIGN=LEFT> " & strMessage & "< /TD> < /TR> ")Response.Write("< TR> < TD ALIGN=RIGHT> < B> 网络打印机路径:< /B> < /TD> ")Response.Write("< TD ALIGN=LEFT> " & strPrinterPath & "< /TD> < /TR> ")Response.Write("< TR> < TD ALIGN=RIGHT> < B> 登录帐号:< /B> < /TD> ")Response.Write("< TD ALIGN=LEFT> " & strUsername & "< /TD> < /TR> ")Response.Write("< /TABLE> ")Response.Write("< /CENTER> ")End If' 取消打印连接objWSHNet.RemovePrinterConnection "LPT1:"Set objWSHNet = NothingSet objFS = NothingSet objPrinter = NothingEnd If%> < /BODY> < /HTML> MVC 用过xVal验证框架的请进,100分求助 asp.net中上传图片时提示:对路径“xxx”的访问被拒绝。 ValidateRequest="false"已经设置成这样,为何提交到数据库中的没有HTML代码? 在从服务器接收结果时发生传输级错误 有新的分页控件嘛? 导入导出 xmlhttp 服务器接收数据 为什么?关于打开窗口的问题! asp.net实现整型字符串求和 当在客户端改变服务器控件的值了,页面postback如何保存客户端的状态?(高分相送) 在datalist中绑定checkbox如何控制checkbox呢? 关于水晶报表
try
{
string sql=getSql(start.Text,end.Text);
//System.Data.OleDb.OleDbConnection conn=new System.Data.OleDb.OleDbConnection("PROVIDER=OraOLEDB.Oracle;DATA SOURCE=new;USER ID=fscrmsa;PASSWORD=s;PLSQLRSet=1");
string ConnectionString=fscrm.include.db.ConnectionString;
System.Data.OleDb.OleDbConnection conn=new
//产生一个相关报表对象。
System.Data.OleDb.OleDbConnection(ConnectionString);
fscrm.psales.rpt.dhbb_1 oRpt = new fscrm.psales.rpt.dhbb_1();
System.Data.OleDb.OleDbDataAdapter comm=new System.Data.OleDb.OleDbDataAdapter(sql,conn);
DataSet ds = new DataSet();
comm.Fill(ds,"table");
oRpt.SetDataSource(ds.Tables["table"]);
ExportOptions crExportOptions=new ExportOptions();
DiskFileDestinationOptions crDiskFileDestinationOptions = new DiskFileDestinationOptions();
string path=Request.ServerVariables["APPL_PHYSICAL_PATH"];
path=path.Replace("\\","\\\\");
string Fname1="zxh"+System.DateTime.Now.Year+System.DateTime.Now.Month+System.DateTime.Now.Day+
System.DateTime.Now.Hour+System.DateTime.Now.Minute+System.DateTime.Now.Second+System.DateTime.Now.Millisecond+".pdf";
string Fname=path+"temp\\"+Fname1;crDiskFileDestinationOptions.DiskFileName = Fname;
oRpt.ExportOptions.DestinationOptions=crDiskFileDestinationOptions;
oRpt.ExportOptions.ExportDestinationType=ExportDestinationType.DiskFile;
oRpt.ExportOptions.ExportFormatType=ExportFormatType.PortableDocFormat;
oRpt.Export();string aa="window.open('/temp/"+Fname1+"')";
Response.Write("<script language='JavaScript'>"+"\n");
Response.Write(aa);
Response.Write("</script>"+"\n");
}
catch{return;}
您好,是我表达有误,我所谓的报表打印,实际上就是打印HTML文件,只不过打印出来的形式是报表样式。
顺便问一下,c/s是client/server结构,而b/s是什么呢?
再打印该html文件,window.print()
再打印该html文件,window.print()
这位大哥回答的可真及时,小弟手头也一些有这方面的资料,只是不够系统,还没有融汇贯通。只是希望有人能有现成的好的方法,可供参考和交流!
技术选择由于.NET framework的winform可以直接嵌入到网页中,这么做并不代表.NET winform是唯一的选择,其实您可以采用任何客户端代替它,例如Java Applet或者ActiveX,甚至是一个普通的应用程序都能行。不允许直接连接到数据库,因此只能采用XML文件进行中间数据交换格式,通过普通WEB服务器的默认80端口进行数据传输。当然,web service也许能算是一种,但是它采用的是SOAP传输数据.
采用.NET编写的受控组件,优点在于:1. 它不需要进行客户端注册。相对于ActiveX的一个大优点。2. 比ActiveX安全性高。在.NET Common Language Runtime的控制之下运行3. 编写方便。我喜欢C#和Visual Studio .NET。4. 有很强大的打印控制功能。利用.NET framework类库。5. 直接支持XML技术。6. 和IE兼容性高。同为Microsoft公司产品。
QQ:35839994,MSN:[email protected]
谢谢大哥的支持!
ASP在电子商务上应用广泛,报表的处理又有一些麻烦。本文介绍了在ASP中利用
本人写的Report Server Page脚本解释器实现报表的显示、打印。
二、准备工作
(1)安装Visual Reprort Design软件
Visual Report Design是本人写的一个免费的报表设计器,程序的发行只需要
安装一个60K的控件即可。
想要的网友可以到http://go.163.com/reportpro/下载
(2)设计报表
通过Visual Report Design 的可视化界面可以生成报表的脚本:mxb.rsp。
三、实现报表的打印、显示
下面是调用的文档:
printmx.asp
<%Option Explicit%>
<%
dim ReportName,ret
dim ReportAtl
dim name
set ReportAtl=Session("ReportAtl")
ReportName=Server.MapPath("mxb.rsp")
ret=reportatl.XMLToVBS(ReportName)
if ret=-1 then
response.write reportatl.ErrorMsg
response.end
end ifReportName=Server.MapPath("mxb.vbs")
ret=reportatl.DoScript(ReportName)
if ret=-1 then
response.write reportatl.ErrorMsg
set ReportAtl=nothing
response.end
end if
set ReportAtl=nothing
%>
<html>
<OBJECT id=reportatl classid="clsid:D3F064E5-F4C0-4C52-9E7F-263D96B7EA11" codebase="Report.cab#version=1,0,0,1">
</OBJECT>
<script language=vbscript>
dim ret
ret=reportatl.DoPrintReport("mxb.zcg")
if ret=-1 then
msgbox reportatl.ErrorMsg
end if
</script>
</html> 用Visual Report Design 产生的报表脚本mxb.rsp:<?xml version='1.0' encoding='GB2312' ?><!DOCTYPE report SYSTEM 'print_report.dtd' ><report name='报表'><report_script>dim rs,con,sql,lsh
dim temp
set con =CreateObject("ADODB.Connection")
con.ConnectionString = "DBQ=c:\report\demo\asp\report.mdb;DRIVER={Microsoft Access Driver (*.mdb)};"
con.open
Set rs =CreateObject("ADODB.Recordset")
sql="SELECT * FROM cj,student where cj.id=student.id "
rs.open sql,con,1,3</report_script><report_head height='12'><text name='vfptext' top='4' left='76' width='26' height='5' font_name='宋体' font_size='14' font_weight='700' font_italic='0' font_underline='0' >成绩明细表</text></report_head><page_head height='6'><line name='vfpline' top='0' left='9' width='178' height='0' weight='131072'></line><line name='vfpline' top='6' left='9' width='178' height='0' weight='131072'></line><text name='vfptext' top='2' left='18' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >姓名</text><text name='vfptext' top='2' left='46' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >语文</text><text name='vfptext' top='2' left='72' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >数学</text><text name='vfptext' top='2' left='99' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >英语</text><text name='vfptext' top='2' left='162' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >合计</text><text name='vfptext' top='2' left='130' width='6' height='3' font_name='宋体' font_size='9' font_weight='700' font_italic='0' font_underline='0' >平均</text></page_head><page_body height='8'><text name='vfptext' top='2' left='15' width='25' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> Report.Write cstr(rs("xm"))</report_script></text><text name='vfptext' top='2' left='45' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> Report.Write cstr(rs("yw"))</report_script></text><text name='vfptext' top='2' left='71' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> Report.Write cstr(rs("sx"))</report_script></text><text name='vfptext' top='2' left='98' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> Report.Write cstr(rs("yy"))</report_script></text><text name='vfptext' top='2' left='130' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> Report.Write cstr((rs("yw")+rs("sx")+rs("yy"))/3)</report_script></text><text name='vfptext' top='2' left='162' width='18' height='4' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> Report.Write cstr(rs("yw")+rs("sx")+rs("yy"))</report_script></text></page_body><page_foot height='7'><text name='vfptext' top='2' left='12' width='13' height='3' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' ><report_script> report.write "打印日期:"+formatdatetime(date(),1)</report_script></text><text name='vfptext' top='2' left='137' width='50' height='3' font_name='宋体' font_size='9' font_weight='100' font_italic='0' font_underline='0' >共%Pages%页,第%Page%页</text><line name='vfpline' top='0' left='8' width='178' height='0' weight='131072'></line></page_foot><report_script>do while not rs.eof
page_body()
rs.movenext
loop
rs.close
set rs=nothing
con.close
set con=nothing</report_script>
</report>
< %
Option ExplicitDim strSubmit 'Form中用来保存提交按钮的值
Dim strPrinterPath 'Form中保存网络打印机路径的值
Dim strUsername 'Form中用户名的值
Dim strPassword 'Form中密码的值
Dim strMessage 'Form打印内容的值
Dim objFS 'VBScript中的文件系统对象
Dim objWSHNet 'WSH中的网络对象
Dim objPrinter '打印对象strSubmit = Request.Form("Submit")
%> < HTML>
< HEAD>
< META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
< /HEAD>
< BODY> < %
If strSubmit = "" Then
%> 注意的是:
由于这是演示,其中有关NT的帐号和密码都是使用了不加密的手段在ASP中传递的
真正的运用中应该对该登录过程进行安全处理。
< FORM action="ASPPrint.asp" method=POST id=form name=form>
< TABLE WIDTH=100% ALIGN=center BORDER=0 CELLSPACING=1 CELLPADDING=1>
< TR>
< TD ALIGN=right NOWRAP> 网络打印机路径:< /TD>
< TD ALIGN=left NOWRAP> < INPUT type="text" id=printerpath name=printerpath
value="< Domain > < Printer > "> < /TD>
< /TR>
< TR>
< TD ALIGN=right NOWRAP> 登录帐号:< /TD>
< TD ALIGN=left NOWRAP> < INPUT type="text" id=username name=username
value="< % = strUsername %> "> < /TD>
< /TR>
< TR>
< TD ALIGN=right NOWRAP> 登录口令:< /TD>
< TD ALIGN=left NOWRAP> < INPUT type="password" id=password
name=password> < /TD>
< /TR>
< TR>
< TD ALIGN=right NOWRAP> 请输入你想打印的文字:< /TD>
< TD ALIGN=left NOWRAP> < TEXTAREA rows=2 cols=20 id=message
name=message> < /TEXTAREA> < /TD>
< /TR>
< TR>
< TD ALIGN=right NOWRAP> < /TD>
< TD ALIGN=left NOWRAP> < INPUT type="submit" value="Submit"
id=submit name=submit> < /TD>
< /TR>
< /TABLE>
< /FORM> 当以上信息被提交后,就可以按照下面的代码进行打印了。
< %
Else
' 从form中取得响应信息。
strPrinterPath = Request.Form("printerpath")
strUsername = Request.Form("username")
strPassword = Request.Form("password")
strMessage = Request.Form("message")We will now use the VBScript FileSystemObject object and the WSH Network object. The Network object will
give us the methods we need to open a printer connection, and the FileSystemObject will allow us to stream our
output to the printer. We create these objects in the following code example: Set objFS = CreateObject("Scripting.FileSystemObject")
Set objWSHNet = CreateObject("WScript.Network")
' 使用WSH连接网络打印机
objWSHNet.AddPrinterConnection "LPT1", strPrinterPath, False, strUsername, strPassword
' 使用文件系统对象将打印设备作为一个文件使用
Set objPrinter = objFS.CreateTextFile("LPT1:", True)
' 给打印设备送出文本
objPrinter.Write(strMessage)
'关闭打印设备对象并进行错误陷阱处理
On Error Resume Next
objPrinter.Close
' 如果发生错误,关闭打印连接,并输出错误信息
If Err Then
Response.Write ("Error # " & CStr(Err.Number) & " " & Err.Description)
Err.Clear
Else
' 操作成功,输出确认信息
Response.Write("< CENTER> ")
Response.Write("< TABLE WIDTH=100% ALIGN=center BORDER=0 CELLSPACING=1 CELLPADDING=1> ")
Response.Write("< TR> < TD ALIGN=RIGHT> < B> 打印消息送出:< /B> < /TD> ")
Response.Write("< TD ALIGN=LEFT> " & strMessage & "< /TD> < /TR> ")
Response.Write("< TR> < TD ALIGN=RIGHT> < B> 网络打印机路径:< /B> < /TD> ")
Response.Write("< TD ALIGN=LEFT> " & strPrinterPath & "< /TD> < /TR> ")
Response.Write("< TR> < TD ALIGN=RIGHT> < B> 登录帐号:< /B> < /TD> ")
Response.Write("< TD ALIGN=LEFT> " & strUsername & "< /TD> < /TR> ")
Response.Write("< /TABLE> ")
Response.Write("< /CENTER> ")
End If
' 取消打印连接
objWSHNet.RemovePrinterConnection "LPT1:"
Set objWSHNet = Nothing
Set objFS = Nothing
Set objPrinter = Nothing
End If
%>
< /BODY>
< /HTML>