请问如何用asp实现打印功能?

loneboy 2002-03-27 05:13:27
请问如何用asp实现打印功能?
我的意思是说实现word的那种打印效果。
并不是简单的window.print().
谢谢
...全文
76 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
y1g1y1 2002-04-27
  • 打赏
  • 举报
回复
http://ygyuan.go.163.com/
http://ygyuan.3322.net/

有控件及演示程序.
julyclyde 2002-03-27
  • 打赏
  • 举报
回复
ASP不能实现打印
zijun28 2002-03-27
  • 打赏
  • 举报
回复
你去搜索一下“打印”这个关键字,你一定会找到你想要的~~`我以前也是的~~后来查找了一下实现了~祝你好运~~
jinhaiou 2002-03-27
  • 打赏
  • 举报
回复
ASP,WSH,VBScript
文件ASPPrint.asp代码如下:
<%@ Language=VBScript %>
<%
Option Explicit

Dim 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>
jinhaiou 2002-03-27
  • 打赏
  • 举报
回复
ASP,WSH,VBScript
文件ASPPrint.asp代码如下:
<%@ Language=VBScript %>
<%
Option Explicit

Dim 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>

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧