VB按钮怎么实现打印功能,打印word文档

VB按钮怎么实现打印功能,打印word文档,第1张

 在Word2007中,用户可以通过设置打印选项使打印设置更适合实际应用,且所做的设置适用于所有Word文档。在Word2007中设置Word文档打印选项的步骤如下所述:
步骤/方法
第1步,打开Word2007文档窗口,依次单击Office按钮→“Word选项”按钮。
第2步,在打开的“Word选项”对话框中,切换到“显示”选项卡。在“打印选项”区域列出了可选的打印选项,选中每一项的作用介绍如下:
(1)选中“打印在Word中创建的图形”选项,可以打印使用Word绘图工具创建的图形;
(2)选中“打印背景色和图像”选项,可以打印为Word文档设置的背景颜色和在Word文档中插入的;
(3)选中“打印文档属性”选项,可以打印Word文档内容和文档属性内容(例如文档创建日期、最后修改日期等内容);
(4)选中“打印隐藏文字”选项,可以打印Word文档中设置为隐藏属性的文字;
(5)选中“打印前更新域”选项,在打印Word文档以前首先更新Word文档中的域;
(6)选中“打印前更新链接数据”选项,在打印Word文档以前首先更新Word文档中的链接,
第3步,在“Word选项”对话框中切换到“高级”选项卡,在“打印”区域可以进一步设置打印选项,选中每一项的作用介绍如下:
(1)选中“使用草稿品质”选项,能够以较低的分辨率打印Word文档,从而实现降低耗材费用、提高打印速度的目的;
(2)选中“后台打印”选项,可以在打印Word文档的同时继续编辑该文档,否则只能在完成打印任务后才能编辑;
(3)选中“逆序打印页面”选项,可以从页面底部开始打印文档,直至页面顶部;
(4)选中“打印XML标记”选项,可以在打印XML文档时打印XML标记;
(5)选中“打印域代码而非域值”选项,可以在打印含有域的Word文档时打印域代码,而不打印域值;
(6)选中“打印在双面打印纸张的正面”选项,当使用支持双面打印的打印机时,在纸张正面打印当前Word文档;
(7)选中“在纸张背面打印以进行双面打印”选项,当使用支持双面打印的打印机时,在纸张背面打印当前Word文档;
(8)选中“缩放内容以适应A4或85”X11”纸张大小”选项,当使用的打印机不支持Word页面设置中指定的纸张类型时,自动使用A4或85”X11”尺寸的纸张;
(9)“默认纸盒”列表中可以选中使用的纸盒,该选项只有在打印机拥有多个纸盒的情况下才有意义。

这是我写的一个例子,Ddh是查询用的,你可以不要,如果数据多的话,考虑分页
调用:
call caigoudd(printer,"0001") '打印
也可以用框显示
call caigoudd(picture1,"0001") '显示
Sub CaiGoudd(Obj As Object, ByVal Ddh As String) '打印采购单
Dim Shang As Integer, Zhuo As Integer '边距
Dim Cangmin As String, Addr As String, Tel As String, Fax As String
Dim Hen As Single, Su As Single, Hh As Single, Hh1 As Single, Beisu As Single, Ss As Single, mm As Single
Dim Gongfa As String
Dim i As Integer, nn As Integer, Rsnum As Integer

Dim Rs As New ADODBRecordset '采购信息
Dim RS1 As New ADODBRecordset '供方信息
Dim sqlStr As String

Set Cn = New ADODBConnection
CnCursorLocation = adUseClient
CnOpen cnStr
sqlStr = "select from cgjl where 订单号码 like '" & Ddh & "'"
RsOpen sqlStr, Cn, adOpenStatic, adLockReadOnly
If RsEOF Then
MsgBox "订单号码不存在,请教对!", , "注意"
RsClose
CnClose
Exit Sub
End If
Rsnum = RsRecordCount
If Rsnum > 6 Then
MsgBox "采购物品大于6条,请用不同的订单号。", , "注意"
RsClose
CnClose
Exit Sub
End If

sqlStr = "select from gfxx where 供方简称 like '" & RsFields("供方名称") & "'"
RS1Open sqlStr, Cn '供方资料
If RS1EOF Then
MsgBox "供方信息不存在,请添加!", , "注意"
RsClose
RS1Close
CnClose
Exit Sub
End If

Ddh = "NO: " & Ddh
Cangmin = "电器有限公司"
Addr = "浙江省"
Tel = "222222222"
Fax = "222222222"

With Obj
ScaleMode = 6 '度量单位为mm

mm = ScaleWidth / 210 '210是A4纸的宽度,mm是显示倍数
Shang = 25 mm
Zhuo = 15 mm
nn = 12 mm
Beisu = (ObjScaleWidth - 2 Zhuo) / nn

DrawWidth = IIf(TypeName(Obj) = "Printer", 7, 1) '线宽度
FontName = "楷体_GB2312"
FontSize = 20 mm
'打印表头
Hen = ScaleWidth
Su = ScaleHeight
CurrentX = (ScaleWidth - TextWidth(Cangmin)) / 2 '居中
CurrentY = Shang
ObjPrint Cangmin
CurrentX = (ScaleWidth - TextWidth("采购订单")) / 2
CurrentY = CurrentY + 3 mm
ObjPrint "采购订单"
FontName = "宋体"
FontSize = 14 mm
CurrentY = CurrentY + 3 mm
CurrentX = Zhuo
ObjPrint " RHF74-07A";
CurrentX = Hen - TextWidth(Ddh) - Zhuo - 3 mm
ObjPrint Ddh
'画表格
Hh = Zhuo '表格左上角坐标
Ss = CurrentY + 3 mm

For i = 0 To 9
ObjLine (Hh, Ss + i nn)-(Hen - Zhuo, Ss + i nn) '横线
Next
ObjLine (Hh, Ss + 125 nn)-(Hen - Zhuo, Ss + 125 nn)
ObjLine (Hh, Ss + 18 nn)-(Hen - Zhuo, Ss + 18 nn)

ObjLine (Hh, Ss)-(Hh, Ss + 18 nn) '竖线
ObjLine (Hen - Zhuo, Ss)-(Hen - Zhuo, Ss + 18 nn)
ObjLine (Hh + nn, Ss + 2 nn)-(Hh + nn, Ss + 9 nn)
ObjLine (Hh + 35 nn, Ss)-(Hh + 35 nn, Ss + 9 nn)
ObjLine (Hh + 7 nn, Ss + 2 nn)-(Hh + 7 nn, Ss + 9 nn)
ObjLine (Hh + 8 nn, Ss + 2 nn)-(Hh + 8 nn, Ss + 9 nn)
ObjLine (Hh + 95 nn, Ss + 2 nn)-(Hh + 95 nn, Ss + 9 nn)
ObjLine (Hh + 115 nn, Ss + 2 nn)-(Hh + 115 nn, Ss + 9 nn)
ObjLine (Hen / 2, Ss + 125 nn)-(Hen / 2, Ss + 18 nn)
'填数据
Hh1 = (nn - TextHeight("供")) / 2
CurrentX = Hh + (35 nn - TextWidth("供方单位")) / 2
CurrentY = Ss + Hh1
ObjPrint "供方单位";
CurrentX = Hh + 35 nn + ((Beisu - 35) nn - TextWidth(RS1Fields("供方全称") & "")) / 2
ObjPrint RS1Fields("供方全称") & ""
CurrentX = Hh + (35 nn - TextWidth("传真号码")) / 2
CurrentY = Ss + nn + Hh1
ObjPrint "传真号码";
CurrentX = Hh + 35 nn + ((Beisu - 35) nn - TextWidth(RS1Fields("传真") & "")) / 2
ObjPrint RS1Fields("传真") & ""

CurrentX = Hh + (nn - TextWidth("序号")) / 2
CurrentY = Ss + 2 nn + Hh1
ObjPrint "序号";
CurrentX = Hh + nn + (25 nn - TextWidth("品 名")) / 2
ObjPrint "品 名";
CurrentX = Hh + 35 nn + (35 nn - TextWidth("规格型号")) / 2
ObjPrint "型号规格";
CurrentX = Hh + 7 nn + (nn - TextWidth("单位")) / 2
ObjPrint "单位";
CurrentX = Hh + 8 nn + (15 nn - TextWidth("数量")) / 2
ObjPrint "数量";
CurrentX = Hh + 95 nn + (2 nn - TextWidth("交货日期")) / 2
ObjPrint "交货日期";
CurrentX = Hh + 115 nn + ((Beisu - 115) nn - TextWidth("备 注")) / 2
ObjPrint "备 注"

FontSize = 12 mm
Hh1 = (nn - TextHeight("供")) / 2
For i = 1 To Rsnum
CurrentX = Hh + (nn - TextWidth(Format(i))) / 2
CurrentY = Ss + (2 + i) nn + Hh1
ObjPrint Format(i);
CurrentX = Hh + nn + (25 nn - TextWidth(RsFields("产品名称"))) / 2
ObjPrint RsFields("产品名称");
CurrentX = Hh + 35 nn + (35 nn - TextWidth(RsFields("规格型号"))) / 2
ObjPrint RsFields("规格型号");
CurrentX = Hh + 7 nn + (nn - TextWidth(RsFields("单位"))) / 2
ObjPrint RsFields("单位");
CurrentX = Hh + 8 nn + (15 nn - TextWidth(Format(RsFields("采购数量")))) / 2
ObjPrint Format(RsFields("采购数量"));
CurrentX = Hh + 95 nn + (2 nn - TextWidth(RsFields("交货日期"))) / 2
ObjPrint RsFields("交货日期");
CurrentX = Hh + 115 nn + ((Beisu - 115) nn - TextWidth(RsFields("备注"))) / 2
ObjPrint RsFields("备注")

RsMoveNext
Next
RsClose
RS1Close
CnClose
CurrentY = Ss + 9 nn
ObjPrint
CurrentX = Hh + 3 mm
ObjPrint "注:"
ObjPrint
CurrentX = Hh + 3 mm
ObjPrint "1 因供方产品质量问题引起的客户索赔及未按时交货引起的经济损失由供方承担。"
ObjPrint
CurrentX = Hh + 3 mm
ObjPrint "2 接到采购单后请速盖章回签,如两天内不回签视同交货期默认。"
ObjPrint
CurrentX = Hh + 3 mm
ObjPrint "3 价格:"

FontSize = 14 mm

CurrentY = Ss + 125 nn
ObjPrint
CurrentX = Hh + 3 mm
ObjPrint "需方单位(章)";
CurrentX = ScaleWidth / 2 + 3 mm
ObjPrint "供方单位(章)"
ObjPrint

CurrentX = Hh + 3 mm
ObjPrint " "; Cangmin
CurrentY = CurrentY + 05 TextHeight("A")
CurrentX = Hh + 3 mm
FontSize = 12 mm
ObjPrint "地 址:"; Left(Addr, 11)
CurrentY = CurrentY + 05 TextHeight("A")
CurrentX = Hh + 3 mm
ObjPrint " "; Right(Addr, 8)
CurrentY = CurrentY + 05 TextHeight("A")
CurrentX = Hh + 3 mm
ObjPrint "电 话:"; Tel
CurrentY = CurrentY + 05 TextHeight("A")
CurrentX = Hh + 3 mm
ObjPrint "传 真:"; Fax
CurrentY = CurrentY + 05 TextHeight("A")
CurrentX = Hh + 3 mm
ObjPrint "联系人:"
ObjPrint

CurrentX = ScaleWidth / 2 - TextWidth(Format(Date, "yyyy年mm月dd日 "))
ObjPrint Format(Date, "yyyy年mm月dd日");
CurrentX = ScaleWidth - Zhuo - TextWidth("年 月 日 ")
ObjPrint "年 月 日"
If TypeName(Obj) = "Printer" Then
EndDoc
End If

End With
End Sub

不用设置的,只要把打印内容输出到Printer对象即可:
PrinterPrint
"你好,这行文字会出现在打印机中"
Printer
PaintPicture
LoadPicture
("123jpg"),
0,
0
'这个会打印123jpg这个
PrinterLine
(0,
0)-(0,
3000),
vbBlack
'这是在打印机上画直线
PrinterCircle
(1500,
1500),
900,
vbBlack
'这是画圆
PrinterEndDoc
'运行这条命令后,上述内容就会在打印机真正打印出来。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/13126399.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-06-05
下一篇 2023-06-05

发表评论

登录后才能评论

评论列表(0条)

保存