在VB中如何实现打印的功能 如何用VB实现表格打印功能?

vb\u5b9e\u73b0\u6253\u5370\u529f\u80fd\u5177\u4f53\u70b9

\u6700\u65b9\u4fbf\u540c\u65f6\u4e5f\u662f\u6700\u7075\u6d3b\u7684\u6253\u5370\u65b9\u5f0f\u662f\u76f4\u63a5\u5229\u7528VB\u7684Printer\u5bf9\u8c61\uff0c\u53ea\u8981\u628a\u5e73\u65f6\u7528Print\u547d\u4ee4\u8f93\u51fa\u5230\u7a97\u4f53\u7684\u5185\u5bb9\u76f4\u63a5\u53d1\u5230Printer\u5bf9\u8c61\u5373\u53ef\uff1a

Printer.Print "\u8981\u6253\u5370\u7684\u5185\u5bb9\u653e\u5728\u8fd9\u91cc"
Printer.Print "\u6253\u5370\u7684\u5185\u5bb9\u53ef\u4ee5\u5206\u591a\u884c\u8f93\u51fa"
Printer.Print "\u4e5f\u53ef\u4ee5\u628a\u6253\u5370\u5185\u5bb9\u653e\u5230\u53d8\u91cf\u4e2d\uff0c\u6bd4\u5982\u540e\u9762\u7684\u8fd9\u4e2ax"; x
Printer.PaintPicture LoadPicture("\u56fe\u7247\u6587\u4ef6\u540d"), 0, 0 '\u8fd8\u53ef\u4ee5\u76f4\u63a5\u5728\u6253\u5370\u673a\u4e2d\u8f93\u51fa\u56fe\u7247
Printer.Line (0, 0) - (3000, 2100) '\u8fd8\u53ef\u4ee5\u753b\u7ebf\u3001\u753b\u5706\u7b49\u7b49\uff0c\u8ddf\u5c4f\u5e55\u8f93\u51fa\u662f\u5b8c\u5168\u4e00\u6837\u7684
Printer.EndDoc '\u8fd9\u4e2a\u547d\u4ee4\u53ef\u4ee5\u628a\u4e0a\u9762\u8981\u6253\u5370\u7684\u5185\u5bb9\u771f\u6b63\u53d1\u5f80\u6253\u5370\u673a

VB\u4e0b\u6570\u636e\u62a5\u8868\u6253\u5370\u8f93\u51fa\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e00\u662f\u901a\u8fc7\u81ea\u5df1\u7684\u8bbe\u8ba1\u548c\u7f16\u7a0b\u5b8c\u6210\u62a5\u8868\u6253\u5370\u8f93\u51fa\u3002\u4e8c\u662f\u901a\u8fc7MS OFFICE\u5b9e\u73b0\u62a5\u8868\u6253\u5370\u8f93\u51fa\u3002\u4e09\u662f\u5e94\u7528\u6570\u636e\u62a5\u8868\u8bbe\u8ba1\u5668\u7684\u62a5\u8868\u6253\u5370\u8f93\u51fa\u3002\u672c\u4eba\u7ecf\u5e38\u4f7f\u7528\u7b2c\u4e00\u79cd\u65b9\u6cd5\uff0c\u5b83\u5177\u6709\u6839\u636e\u9700\u8981\u7075\u6d3b\u5e94\u7528\u7684\u7279\u70b9\uff0c\u4f46\u9700\u7f16\u5199\u7a0b\u5e8f\u3002\u4e0b\u9644\u4ee3\u7801\uff0c\u7b2c\u4e00\u6bb5\u4ee3\u7801\u5b9a\u4e49\u57fa\u672c\u53d8\u91cf\uff0c\u7b2c\u4e8c\u6bb5\u4ee3\u7801\u5b9a\u4e49\u6253\u5370\u51fd\u6570\uff0c\u7b2c\u4e09\u6bb5\u4ee3\u7801\u662f\u5177\u4f53\u6253\u5370\u4ee3\u7801\uff0c\u542b\u6570\u636e\u8f6c\u6362\u3002\u7b2c\u56db\u6bb5\u4ee3\u7801\u662f\u7a97\u4f53\u52a0\u8f7d\u4ee3\u7801\uff0c\u5177\u4f53\u8fde\u63a5\u6570\u636e\u5e93\u548c\u6253\u5370\u4ee3\u7801\u6839\u636e\u4f60\u6240\u6d89\u53ca\u7684\u6570\u636e\u8981\u6c42\u8fdb\u884c\u4fee\u6539\u3002
Option Explicit
Private n As Integer
Private m As Integer
Private zh_dm(10) As Double
Private dy_dm(3000, 10) As Variant
Private zsl As Integer
Private y As Integer
Private x As Integer
Private i As Integer
Private k As Integer
Private p As Integer
Private pa As Integer
Private j As Integer
Private txt As String
Private fnt As Integer
Private dd As Variant

Public Function prnt(x As Variant, y As Variant, fnt As Variant, txt0 As Variant)
Printer.CurrentX = x
Printer.CurrentY = y
Printer.FontSize = fnt
Printer.Print txt0
End Function

Private Sub cmdPrint_Click()
Adodc1.Recordset.MoveFirst
For i = 0 To zsl - 1
For j = 0 To 7
dy_dm(i, j) = Adodc1.Recordset(j)
Next j
Adodc1.Recordset.MoveNext
Next i
'\u786e\u5b9a\u9875\u6570
k = Int(zsl / 80)'80\u4e3a\u6bcf\u9875\u884c\u6570
If k - zsl / 80 < 0 Then
k = k + 1
End If

fnt = 8
For p = 0 To k - 1
pa = p + 1
y = 300
x = 4500
txt = "\u673a\u7269\u6599\u5e93\u5b58"
dd = prnt(x, y, fnt, txt)
x = 8500
txt = "\u7b2c" & p + 1 & "\u9875"
dd = prnt(x, y, fnt, txt)
y = 500
x = 600
txt = "\u5907\u4ef6\u4ee3\u7801"
dd = prnt(x, y, fnt, txt)
x = 1500
txt = "\u5907\u4ef6\u540d\u79f0"
dd = prnt(x, y, fnt, txt)
x = 3500
txt = "\u5907\u4ef6\u89c4\u683c"
dd = prnt(x, y, fnt, txt)
x = 5500
txt = "\u8fdb\u53e3\u8ba1\u7b97\u673a\u53f7"
dd = prnt(x, y, fnt, txt)
x = 7500
txt = "\u6700\u4f4e\u50a8\u5907\u91cf"
dd = prnt(x, y, fnt, txt)
x = 9000
txt = "\u5e93\u5b58\u91cf"
dd = prnt(x, y, fnt, txt)

For i = 0 + p * 80 To 79 + p * 80
y = 700 + 180 * (i - p * 80)
x = 600
txt = dy_dm(i, 1)
dd = prnt(x, y, fnt, txt)
x = 1500
txt = dy_dm(i, 2)
dd = prnt(x, y, fnt, txt)
x = 3500
txt = dy_dm(i, 3)
dd = prnt(x, y, fnt, txt)
x = 5500
txt = dy_dm(i, 4)
dd = prnt(x, y, fnt, txt)
x = 7500
txt = dy_dm(i, 5)
dd = prnt(x, y, fnt, txt)
x = 9000
txt = dy_dm(i, 6)
dd = prnt(x, y, fnt, txt)
If Int(i / 10) - i / 10 = 0 Then
Printer.Line (500, 695 + (i - p * 80) * 180)-(10000, 695 + (i - p * 80) * 180)
End If
Next i
If zsl - p * 80 > 80 Then
Printer.Line (500, 695 + 180 * 80)-(10000, 695 + 180 * 80)
Printer.NewPage
End If
Next p
Printer.EndDoc ' \u6253\u5370\u5b8c\u6210\u3002
Cls
End Sub

Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=jwl_dbf"
Adodc1.RecordSource = "select cs.js_dm,cs.\u5907\u4ef6\u4ee3\u7801,cs.\u5907\u4ef6\u540d\u79f0,cs.\u5907\u4ef6\u89c4\u683c,cs.\u8fdb\u53e3\u8ba1\u7b97\u673a\u53f7,cs.\u6700\u4f4e\u5e93\u5b58\u91cf,sl.\u7ed3\u5b58\u6570\u91cf,sl.\u7ed3\u5b58\u91d1\u989d,sl.\u7ed3\u5b58\u5355\u4ef7,sl.\u7c7b\u522b\u4ee3\u7801 from JWCK_BM as cs,jwl_jiec as sl" & _
" where cs.\u5907\u4ef6\u4ee3\u7801 = sl.\u5907\u4ef6\u4ee3\u7801" & " and cs.\u5907\u4ef6\u4ee3\u7801>" & "''" & " order by sl.\u7c7b\u522b\u4ee3\u7801,sl.\u5907\u4ef6\u4ee3\u7801"
Adodc1.Refresh
DataGrid1.Refresh
zsl = Adodc1.Recordset.RecordCount
Adodc3.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=jwl_dbf"
Adodc3.RecordSource = "select sum(\u7ed3\u5b58\u91d1\u989d) as hj from jwl_jiec"
Adodc3.Refresh
End Sub

\u4ee5\u4e0a\u4f9b\u53c2\u8003\u3002\u5176\u5b83\u8bf7\u53c2\u8003\u897f\u5b89\u4ea4\u901a\u5927\u5b66\u51fa\u7248\u793e\u51fa\u7248\u7684\u201cVISUAL BASIC 6.0 \u9ad8\u7ea7\u7f16\u7a0b\u6280\u5de7-ADO\u6570\u636e\u8bbf\u95ee\u7bc7\u201c

Printer对象
Printer对象可以实现与系统打印机的通信
Printer对象常用的属性有:Height,width,PaperSize,DeviceName等分别表示打印纸的长度,宽度,纸张大小,打印机名称。
Printer对象有三个很重要的方法:EndDoc(开始打印),KillDoc(中断打印)和NewPage(换页).
例如:有一个“注意26日病毒!”提示要打印10份,并加页码,用如下程序段实现:
Private Sub command_Click()
Dim i As Integer
Dim str As String
str="注意26日病毒!"
Printer.FontName="黑体"
Printer.FontSize=26
For i=1 To 10
Printer.Print str
Printer.Print "第 " & Printer.Page & "页"
Printer.NewPage
Next
Printer.EndDoc
End Sub

  • 鍦╒B涓浣曞疄鐜灏嗘暟鎹簱涓殑鏁版嵁鎵撳嵃鍑烘潵
    绛旓細鏁版嵁搴撲腑鐨鏁版嵁鎵撳嵃鍑烘潵鍚楋紵缁欎綘涓涓濊矾锛岄鍏堬紝浣犺鍋氱殑鏄鍙栨暟鎹簱璁板綍锛屽苟鎶婂畠浠繚瀛樿捣鏉ャ傚綋鐒讹紝鍙互鏄繚瀛樺湪鎺т欢涓婏紝涔熷彲浠ヤ繚瀛樺湪鍙橀噺閲銆傚懙鍛碉紝褰撶劧涔熷彲浠ヨ涓鏉¤褰曪紝鎵撳嵃涓娆°備笉杩囪繖鍙兘鏈夌偣閭f牱鈥︹︺傝鍙栧嚭鏉ヤ互鍚庯紝浣犺繕闇瑕佽繘琛屾暟鎹殑鎺掔増锛屾瘮濡備綘闇瑕佹墦鍗版垚浠涔堟牱寮忥紝绾稿紶绫诲瀷绛夈傚仛濂戒簡...
  • VB鎬庢牱璋冪敤鎵撳嵃鏈璁剧疆鎵撳嵃picturebox閲岀殑鍥剧墖
    绛旓細1銆乿b6閲屽彲浠ョ敤Printer瀵硅薄鐨凱aintPicture 鏂规硶瀹炵幇鎵撳嵃picturebox閲岀殑鍥剧墖銆2銆乿b6绀轰緥锛歅rivate Sub Form_DblClick()'瀹炵幇鎵撳嵃鍥惧儚鍒版墦鍗版満Printer.PaintPicture Picture1.Picture, 0, 0Printer.EndDocEnd Sub
  • 鎬!鐢VB瀹炵幇涓涓鎵撳嵃WORD鏂囨。鍔熻兘銆傘傘
    绛旓細VB瀹炵幇鎵撳嵃WORD鏂囨。鍔熻兘鐨鎬濊矾濡備笅锛氫竴銆佽璁′竴涓墦鍗版ā鏉挎枃浠讹紝鍦ㄩ渶瑕佸~鍐欐暟鎹殑鍦版柟浣滄爣璁帮紱浜屻鍦鎵撳嵃鍓嶏紝鍙鍒舵ā鏉挎枃浠跺埌涓涓复鏃舵枃浠讹紝鐒跺悗鎵撳紑姝や复鏃舵ā鏉挎枃浠讹紝鍦ㄦ爣璁板閫氳繃鏇挎崲鍔熻兘濉啓鏁版嵁銆備笁銆佹樉绀烘墦鍗伴夐」瀵硅瘽妗嗭紝杩涜鎵撳嵃杈撳嚭銆備互涓嬫槸绀轰緥婧愪唬鐮侊紝璇蜂笅杞藉弬鑰冿細http://files.7lx.com/data/2010...
  • VB濡備綍鎶婃枃瀛鎵撳嵃鍒板睆骞曚笂?
    绛旓細strText = "Hello !" '灞忓箷鎵撳嵃浣嶇疆 With rt .Left = 500 .Top = 200 .Right = 600 .Bottom = 600 End With lngDC = GetDC(0) DrawText lngDC, strText, Len(strText), rt, 0 ReleaseDC 0, lngDCEnd Sub ...
  • 鍦╒B涓 鎬庝箞鎶婃枃鏈涓綋鍓嶉変腑鐨勫唴瀹鎵撳嵃鍦ㄧ獥浣撲笂
    绛旓細绐椾綋娣诲姞涓涓猅imer鎺т欢锛屼唬鐮佸涓嬶細Private Sub Form_Load()Timer1.Interval = 200 Timer1.Enabled = True End Sub Private Sub Timer1_Timer()If Text1.SelLength > 0 Then Cls Print Mid(Text1, Text1.SelStart + 1, Text1.SelLength)End If End Sub ...
  • vb濡備綍灏嗘暟鎹繚瀛樺埌word涓,骞鎵撳嵃
    绛旓細缂栦釜灏忕▼搴,鎯宠瀹炵幇鍗曞嚮"淇濆瓨"command鏃,灏嗙▼搴忚繍琛屽嚭鏉鐨鏁版嵁淇濆瓨鑷硍ord涓,鍗曞嚮"鎵撳嵃"command鏃,灏嗘word鏂囦欢鎵撳嵃鍑烘潵.璇烽珮鎵嬭祼鏁!璋㈣阿鍝... 缂栦釜灏忕▼搴,鎯宠瀹炵幇鍗曞嚮"淇濆瓨"command鏃,灏嗙▼搴忚繍琛屽嚭鏉ョ殑鏁版嵁淇濆瓨鑷硍ord涓,鍗曞嚮"鎵撳嵃"command鏃,灏嗘word鏂囦欢鎵撳嵃鍑烘潵.璇烽珮鎵嬭祼鏁!璋㈣阿鍝 灞曞紑 ...
  • 姹"鎵撳嵃"鐨刅B浠g爜!
    绛旓細鏄湰浜哄叧浜庢暟鎹簱鏌ヨ杈撳嚭鐨浠g爜,鍙緵鍙傝:VB涓嬫暟鎹姤琛鎵撳嵃杈撳嚭鏂规硶鏈夊绉嶏紝涓鏄氳繃鑷繁鐨勮璁″拰缂栫▼瀹屾垚鎶ヨ〃鎵撳嵃杈撳嚭銆備簩鏄氳繃MS OFFICE瀹炵幇鎶ヨ〃鎵撳嵃杈撳嚭銆備笁鏄簲鐢ㄦ暟鎹姤琛ㄨ璁″櫒鐨勬姤琛ㄦ墦鍗拌緭鍑恒傛湰浜虹粡甯镐娇鐢ㄧ涓绉嶆柟娉曪紝瀹冨叿鏈夋牴鎹渶瑕佺伒娲诲簲鐢ㄧ殑鐗圭偣锛屼絾闇缂栧啓绋嬪簭銆備笅闄勪唬鐮侊紝绗竴娈典唬鐮佸畾涔夊熀鏈彉閲...
  • vb 6.0鎬庝箞鍦ㄥ浘鐗囦腑鍔犲叆鏂囧瓧骞鎵撳嵃
    绛旓細鍙互鐢ㄧ獥浣撳強PictureBox 鎺т欢鍔犺浇鍥剧墖锛屽苟鍦ㄩ渶瑕鐨浣嶇疆濉啓鏂囧瓧锛岀劧鍚鎵撳嵃璇ュ浘鐗囥傚锛氬埄鐢≒ictureBox 鎺т欢 1銆佸姞杞藉浘鐗 Picture1.Picture = LoadPicture("D:\xxxx.jpg")2銆佸湪鍥剧墖涓~鍐欐枃瀛 Picture1.FontSize = 40 Picture1.ForeColor = vbRed Picture1.Print "涓浗(China)"3銆佹墦鍗拌鍥剧墖 Printer....
  • VB搴旂敤绋嬪簭涓墦鍗鏉″舰鐮鐨鏂规硶
    绛旓細,濡傛灉鐜板湪鎴戜滑瑕佸鐞嗕竴寮犺溅绁,涓婇潰涓嶄粎瑕佹墦鍗版潯褰㈢爜,杩樿鏈夌粓鐐圭珯鍜岀エ浠风瓑淇℃伅,閭d箞鎺т欢灏卞彉寰椾笉鍙敤銆傚绋嬪簭鍛樻潵璇,鍙兘杩樻槸甯屾湜鑳戒簡瑙f潯褰㈢爜鎵撳嵃鐨鍘熺悊,鏈枃鎻愬嚭涓ょ鎵撳嵃鏂规硶涓庡悓琛屼滑鎺㈣銆 涓銆佺洿鎺ュ埄鐢ㄦ湁鏉″舰鐮鎵撳嵃鍔熻兘鐨勬墦鍗版満 鏈夎澶氭墦鍗版満鑳藉鐩存帴鎵撳嵃鏉″舰鐮,浣鍦 VB 涓,鎴戜滑鍦―OS鏃朵唬鐔熸倝鐨凩PRINT璇彞宸茬粡涓嶈兘...
  • vb涓殑鎵撳嵃浠g爜
    绛旓細鏈绠鍗鐨锛屽氨鏄細Me.PrintForm 鍚﹀垯锛屼竴涓ゅ彞璇濊繕璇翠笉娓呫傞敊璇偗瀹氭槸涓ラ噸鐨勶紒For i = 0 To DataGrid1 - 1 浣犺繖涓 DataGrid1 鍙郴缁鎬庝箞鐞嗚В锛烡ataGrid1鏄繖涓綉鏍兼帶浠剁殑鍚嶅瓧瀵瑰惂锛熷悕瀛楄繕鍙互鍑1鍟婏紵閭d箞鍚嶅瓧鍑1绛変簬鍑犲憿锛熶綘瑕佽繖鏍鎵撳嵃缁撴灉鐨勮瘽锛屾垜鍛婅瘔浣犺杩欐牱锛欴ataGrid鎺т欢鏈夊垪灞炴э紙Col锛夊拰琛...
  • 扩展阅读:vb5是什么药治疗什么 ... vba自动生成标签打印 ... 药上有vb1下面有10 ... vb1-10是治什么病的 ... vba自动打印参数 ... 在vb中不能关闭的窗口是 ... 一天一粒vb有害吗 ... vba选择指定打印机 ... vb最佳服用时间 ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网