如何在VB.NET打印文档中制作表格 [英] How to make a table in VB.NET printing document
问题描述
您好我想在vb.net中制作一份报告文档,但我无法在文档中创建一个表格。我是新的打印文件在vb和我使用基本代码打印。
我想要打印的文档将如下所示
1 - imgbb.com [ ^ ]
我尝试了什么:
这是我试过的:
2 - imgbb.com [ ^ ]
私人 Sub PrintDocument1_PrintPage(发件人作为 对象,e As Printing.PrintPageEventArgs)句柄 PrintDocument1.PrintPage
Dim Re portFont As Font = 新 Drawing.Font( Bebas Neue, 16 )
Dim ReportBodyFont As Font = 新 Drawing.Font( Bebas Neue, 6 )
< span class =code-comment>' Report'
e.Graphics.DrawImage(My.Resources.logodgn, 580 , 10 , 220 , 50 )
e.Graphics.DrawString( SERVICE完成报告,ReportFont,Brushes.Red, 220 , 40 )
e.Graphics.DrawString( 日期:,ReportFont,Brushes.Black, 450 , 90 )
e.Graphics。 DrawString(datePicker.Text,ReportFont,Brushes.Blue, 510 , 90 )
e。 Graphics.DrawString( 客户端:,ReportFont,Brushes.Black, 50 , 130 )
e.Graphics.DrawString(clientNameText.Text,ReportFont,Brushes.Blue, 120 , 130 )
e.Graphics.DrawString( 时间已开始:,ReportFont,Brushes.Black, 550 , 130 )
e.Graphics.DrawString(时间StartedText.Text,ReportFont,Brushes.Blue, 680 , 130 )
e.Graphics。 DrawString( 联系人:,ReportFont,Brushes.Black, 50 , 160 )
e.Graphics.DrawString(cPersonText.Text,ReportFont,Brushes.Blue, 210 , 160 )
e.Graphics.DrawString( 时间结束:,ReportFont,Brushes.Black, 550 , 160 )
e.Graphics.DrawString(timeEndedText.Text,ReportFont,Brushes.Blue, 680 , 160 )
' '
e。 Graphics.DrawString( 亲爱的先生/女士:,ReportFont,Brushes.Black, 50 , 210 )
e.Graphics.DrawString( Please确认完成所提供的服务。,ReportFont,Brushes.Black, 50 , 250 )
e.Graphics.DrawString( 请参阅此表格,了解所涵盖区域的详细信息和,ReportFont,Brushes.Black, 50 , 280 )
e.Graphics.DrawString( 由我们的服务和使用我们的技术完成。,ReportFont,Brushes.Black, 50 , 310 )
' '
e.Graphics.DrawString( Doclogging, ReportFont,Brushes.Black, 50 , 360 )
e.Graphics.DrawString( 数量,ReportFont,Brushes.Black, 220 , 360 )
e.Graphics.DrawString( Clogged,ReportFont,Brushes.Black, 330 , 360 )
e.Graphics.DrawString( Findings / Remarks,ReportFont,Brushes.Black, 470 , 360 )
' < span class =code-comment>'
e.Graphics.DrawString( Floor Drain,ReportFont,Brushes.Green, 50 , 400 )
e.Graphics.DrawString(fldQuantityText.Text,ReportFont,Brushes.Blue, 220 , 400 )
e.Graphics.DrawString(fldClText.Text,ReportFont,Brushes.Blue, 330 , 400 )
e.Graphics.DrawString(fldFinRecText.Text,ReportFont,Brushes.Blue, 470 , 400 )
' '
e.Graphics.DrawString( Grease Trap,ReportFont ,Brushes.Green, 50 , 430 )
e.Graphics.DrawString(grtQuantityText.Text ,ReportFont,Brushes.Blue , 220 , 430 )
e.Graphics.DrawString(grtClText.Text,ReportFont,Brushes) .Blue, 330 , 430 )
e.Graphics.DrawString(grtFinRecText.Text,ReportFont ,Brushes.Blue, 470 , 430 )
' '
e.Graphics.DrawString( Clean Out,ReportFont,Brushes.Green, 50 , 460 )
e.Graphics.DrawString(coQuantityText.Text,ReportFont,Brushes.Blue, 220 , 460 )
e.Graphics.DrawString(coClText.Text,ReportFont,Brushes.Blue, 330 , 460 )
e.Graphics.Draw字符串(coFinRecText.Text,ReportFont,Brushes.Blue, 470 , 460 )
' '
e.Graphics.DrawString( 厨房清洁,ReportFont,Brushes.Black, 50 , 490 )
' '
e.Graphics .DrawString( Range,ReportFont,Brushes.Green, 50 , 520 )
e.Graphics.DrawString(rngQuantityText.Text,ReportFont,Brushes.Blue, 220 , 520 )
e.Graphics.DrawString(rngClText.Text,ReportFont,Brushes.Blue, 330 , 520 )
e.Graphics.DrawString(rngFinRecText.Text,ReportFont,Brushes.Blue, 470 , 520 )
' '
e.Graphics.DrawString( 烤箱,ReportFont,Brushes.Green, 50 , 550 )
e.Graphics.DrawString(ovnQuantityText.Text,ReportFont,Brushes.Blue, 220 , 550 )
e.Graphics.DrawString(ovnClText.Text,ReportFont,Brushes.Blue,< span class =code-digit> 330 , 550 )
e.Graphics.DrawString(ovnFinRecText.Text,ReportFont,Brushes.Blue , 470 , 550 )
' '
e.Graphics.DrawString( Grill,ReportFont,Brushes.Green,< span class =code-digit> 50 , 580 )
e.Graphics.DrawString(grlQuantityText.Text,ReportFont,Brushes.Blue , 220 , 580 )
e.Graphics.DrawString(grlClText.Text,ReportFont,Brushes) .Blue, 330 , 580 )
e.Graphics.DrawString(grlFinRecText.Text,ReportFont ,Brushes.Blue, 470 , 580 )
' '
e.Graphics.DrawString( Deep-fryer,ReportFont,Brushes.Green, 50 , 610 )
e.Graphics.DrawString(dpfQu antityText.Text,ReportFont,Brushes.Blue, 220 , 610 )
e.Graphics。 DrawString(dpfClText.Text,ReportFont,Brushes.Blue, 330 , 610 )
e。 Graphics.DrawString(dpfFinRecText.Text,ReportFont,Brushes.Blue, 470 , 610 )
' '
e.Graphics.DrawString( 引擎盖,ReportFont,Brushes.Green, 50 , 640 )
e.Graphics.DrawString(hdsQuantityText.Text,ReportFont,Brushes.Blue, 220 , 640 )
e.Graphics.DrawString(hdsClText.Text,ReportFont,Brushes.Blue, 330 , 640 )
e.Graphics.DrawString(hdsFinRecText.Text,ReportFont,Brushes.Blue, 470 , 640 )
' '
e.Graphics .DrawString( D& G Pacific Personnel,ReportFont,Brushes.Black, 300 , 700 )
e.Graphics.DrawString( 1。 + pCB1.Text,ReportFont,Brushes.Blue, 50 , 730 )
e.Graphics.DrawString( 2. + pCB2.Text,ReportFont,Brushes.Blue , 50 , 760 )
e.Graphics.DrawString( 3. + pCB3.Text,ReportFont,Brushes.Blue, 50 , 790 )
e.Graphics.DrawString( 4。 + pCB4.Text,ReportFont,Brushes.Blue, 470 , 730 )
e.Graphics.DrawString( 5. + pCB5.Text, ReportFont,Brushes.Blue, 470 , 760 )
e.Graphics.DrawString( 6。 + pCB6.Text,ReportFont,Brushes.Blue, 470 , 790 )
' '
e.Graphics.DrawString( 服务呈现:,ReportFont,Brushes.Black, 50 , 830 )
e.Graphics.DrawString( Client备注,ReportFont,Brushes.Black, 350 , 830 )
e .Graphics.DrawString( 服务等级,ReportFont,Brushes.Black, 650 , 830 )
' 服务呈现
e.Graphics.DrawString( ▢厨房清洁,ReportFont,Brushes.Black, 50 , 860 )
e.Graphics.DrawString( ▢去堵塞,ReportFont,Brushes.Black, 50 , 890 )
e.Graphics.DrawString( ▢Duct Cleaning,ReportFont,Brushes .Black, 50 , 920 )
e.Graphics.DrawString( 其他,ReportFont,Brushes.Black, 50 ,< span class =code-digit> 950 )
e.Graphics.DrawString( _____________,ReportFont,Brushes.Black, 50 , 980 )
' 客户备注'
e.Graphics.DrawString( _____________________,ReportFont,Brushes .Black, 275 , 860 )
e.Graphics.DrawString( _____________________,ReportFont,Brushes.Black, 275 ,< span class =code-digit> 890 )
e.Graphics.DrawString( _____________________,ReportFont,Brushes.Black, 275 , 920 )
< span class =code-comment>' 服务等级'
e.Graphics.DrawString( __________,ReportFont,Brushes.Black, 650 , 920 )
e.Graphics.DrawString( *范围1-10。,ReportFont,Brushes.Black, 600 , 950 )
e.Graphics.DrawString( 10最高,ReportFont,Brushes.Black, 600 , 980 )
' 签名'
e.Graphics.DrawString( ____________________,ReportFont,Brushes.Black, 300 , 1050 )
e.Graphics.DrawString( 签名打印名称,ReportFont,Brushes.Black, 275 , 1100 )
< span class =code-keyword>结束 Sub
当您使用PrintDocument时,您将获得极大的灵活性和精确度 - 您可以完全控制打印的内容,时间和位置。这使报告看起来完全符合您的要求,但有一个缺点:您必须打印您想要的,您想要的位置 - 您不能使用控件来打印列表数据,并且您有责任确保打印正确页面上的正确信息:您依次获得每页的PrintPage事件,直到您告诉它没有更多页面。
这可能会变得复杂,但这应该是帮助:如何打印数据C#和.NET中的网格
[ ^ ]
代码在C#中,但是它已得到很好的解释并且有在线转换为更原始的语言:代码转换器 [ ^ ]
Hi i want to make a report document in vb.net but i cant manage to create a table in the document. Im new in printing document in vb and im using the basic codes on printing. 这篇关于如何在VB.NET打印文档中制作表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
I want the printed document will look like this
1 — imgbb.com[^]
What I have tried:
This is what i tried:
2 — imgbb.com[^]
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim ReportFont As Font = New Drawing.Font("Bebas Neue", 16)
Dim ReportBodyFont As Font = New Drawing.Font("Bebas Neue", 6)
'Report'
e.Graphics.DrawImage(My.Resources.logodgn, 580, 10, 220, 50)
e.Graphics.DrawString("SERVICE COMPLETION REPORT", ReportFont, Brushes.Red, 220, 40)
e.Graphics.DrawString("Date: ", ReportFont, Brushes.Black, 450, 90)
e.Graphics.DrawString(datePicker.Text, ReportFont, Brushes.Blue, 510, 90)
e.Graphics.DrawString("Client: ", ReportFont, Brushes.Black, 50, 130)
e.Graphics.DrawString(clientNameText.Text, ReportFont, Brushes.Blue, 120, 130)
e.Graphics.DrawString("Time Started: ", ReportFont, Brushes.Black, 550, 130)
e.Graphics.DrawString(timeStartedText.Text, ReportFont, Brushes.Blue, 680, 130)
e.Graphics.DrawString("Contact Person: ", ReportFont, Brushes.Black, 50, 160)
e.Graphics.DrawString(cPersonText.Text, ReportFont, Brushes.Blue, 210, 160)
e.Graphics.DrawString("Time Ended: ", ReportFont, Brushes.Black, 550, 160)
e.Graphics.DrawString(timeEndedText.Text, ReportFont, Brushes.Blue, 680, 160)
''
e.Graphics.DrawString("Dear Sir/Madame: ", ReportFont, Brushes.Black, 50, 210)
e.Graphics.DrawString("Please acknowledge completion of service rendered.", ReportFont, Brushes.Black, 50, 250)
e.Graphics.DrawString("Kindly see this presented form for particulars of areas covered and ", ReportFont, Brushes.Black, 50, 280)
e.Graphics.DrawString("done by our service and use of our technology.", ReportFont, Brushes.Black, 50, 310)
''
e.Graphics.DrawString("Doclogging", ReportFont, Brushes.Black, 50, 360)
e.Graphics.DrawString("Quantity", ReportFont, Brushes.Black, 220, 360)
e.Graphics.DrawString("Clogged", ReportFont, Brushes.Black, 330, 360)
e.Graphics.DrawString("Findings/Remarks", ReportFont, Brushes.Black, 470, 360)
''
e.Graphics.DrawString("Floor Drain", ReportFont, Brushes.Green, 50, 400)
e.Graphics.DrawString(fldQuantityText.Text, ReportFont, Brushes.Blue, 220, 400)
e.Graphics.DrawString(fldClText.Text, ReportFont, Brushes.Blue, 330, 400)
e.Graphics.DrawString(fldFinRecText.Text, ReportFont, Brushes.Blue, 470, 400)
''
e.Graphics.DrawString("Grease Trap", ReportFont, Brushes.Green, 50, 430)
e.Graphics.DrawString(grtQuantityText.Text, ReportFont, Brushes.Blue, 220, 430)
e.Graphics.DrawString(grtClText.Text, ReportFont, Brushes.Blue, 330, 430)
e.Graphics.DrawString(grtFinRecText.Text, ReportFont, Brushes.Blue, 470, 430)
''
e.Graphics.DrawString("Clean Out", ReportFont, Brushes.Green, 50, 460)
e.Graphics.DrawString(coQuantityText.Text, ReportFont, Brushes.Blue, 220, 460)
e.Graphics.DrawString(coClText.Text, ReportFont, Brushes.Blue, 330, 460)
e.Graphics.DrawString(coFinRecText.Text, ReportFont, Brushes.Blue, 470, 460)
''
e.Graphics.DrawString("Kitchen Cleaning", ReportFont, Brushes.Black, 50, 490)
''
e.Graphics.DrawString("Range", ReportFont, Brushes.Green, 50, 520)
e.Graphics.DrawString(rngQuantityText.Text, ReportFont, Brushes.Blue, 220, 520)
e.Graphics.DrawString(rngClText.Text, ReportFont, Brushes.Blue, 330, 520)
e.Graphics.DrawString(rngFinRecText.Text, ReportFont, Brushes.Blue, 470, 520)
''
e.Graphics.DrawString("Oven", ReportFont, Brushes.Green, 50, 550)
e.Graphics.DrawString(ovnQuantityText.Text, ReportFont, Brushes.Blue, 220, 550)
e.Graphics.DrawString(ovnClText.Text, ReportFont, Brushes.Blue, 330, 550)
e.Graphics.DrawString(ovnFinRecText.Text, ReportFont, Brushes.Blue, 470, 550)
''
e.Graphics.DrawString("Grill", ReportFont, Brushes.Green, 50, 580)
e.Graphics.DrawString(grlQuantityText.Text, ReportFont, Brushes.Blue, 220, 580)
e.Graphics.DrawString(grlClText.Text, ReportFont, Brushes.Blue, 330, 580)
e.Graphics.DrawString(grlFinRecText.Text, ReportFont, Brushes.Blue, 470, 580)
''
e.Graphics.DrawString("Deep-fryer", ReportFont, Brushes.Green, 50, 610)
e.Graphics.DrawString(dpfQuantityText.Text, ReportFont, Brushes.Blue, 220, 610)
e.Graphics.DrawString(dpfClText.Text, ReportFont, Brushes.Blue, 330, 610)
e.Graphics.DrawString(dpfFinRecText.Text, ReportFont, Brushes.Blue, 470, 610)
''
e.Graphics.DrawString("Hoods", ReportFont, Brushes.Green, 50, 640)
e.Graphics.DrawString(hdsQuantityText.Text, ReportFont, Brushes.Blue, 220, 640)
e.Graphics.DrawString(hdsClText.Text, ReportFont, Brushes.Blue, 330, 640)
e.Graphics.DrawString(hdsFinRecText.Text, ReportFont, Brushes.Blue, 470, 640)
''
e.Graphics.DrawString("D&G Pacific Personnel", ReportFont, Brushes.Black, 300, 700)
e.Graphics.DrawString("1. " + pCB1.Text, ReportFont, Brushes.Blue, 50, 730)
e.Graphics.DrawString("2. " + pCB2.Text, ReportFont, Brushes.Blue, 50, 760)
e.Graphics.DrawString("3. " + pCB3.Text, ReportFont, Brushes.Blue, 50, 790)
e.Graphics.DrawString("4. " + pCB4.Text, ReportFont, Brushes.Blue, 470, 730)
e.Graphics.DrawString("5. " + pCB5.Text, ReportFont, Brushes.Blue, 470, 760)
e.Graphics.DrawString("6. " + pCB6.Text, ReportFont, Brushes.Blue, 470, 790)
''
e.Graphics.DrawString("Service Rendered:", ReportFont, Brushes.Black, 50, 830)
e.Graphics.DrawString("Client Remarks", ReportFont, Brushes.Black, 350, 830)
e.Graphics.DrawString("Service Grade", ReportFont, Brushes.Black, 650, 830)
'Service Rendered'
e.Graphics.DrawString("▢ Kitchen Cleaning", ReportFont, Brushes.Black, 50, 860)
e.Graphics.DrawString("▢ De-clogging", ReportFont, Brushes.Black, 50, 890)
e.Graphics.DrawString("▢ Duct Cleaning", ReportFont, Brushes.Black, 50, 920)
e.Graphics.DrawString("Other", ReportFont, Brushes.Black, 50, 950)
e.Graphics.DrawString("_____________", ReportFont, Brushes.Black, 50, 980)
'Client Remarks'
e.Graphics.DrawString("_____________________", ReportFont, Brushes.Black, 275, 860)
e.Graphics.DrawString("_____________________", ReportFont, Brushes.Black, 275, 890)
e.Graphics.DrawString("_____________________", ReportFont, Brushes.Black, 275, 920)
'Service Grade'
e.Graphics.DrawString("__________", ReportFont, Brushes.Black, 650, 920)
e.Graphics.DrawString("*Range of 1-10.", ReportFont, Brushes.Black, 600, 950)
e.Graphics.DrawString("10 Being highest", ReportFont, Brushes.Black, 600, 980)
'Signature'
e.Graphics.DrawString("____________________", ReportFont, Brushes.Black, 300, 1050)
e.Graphics.DrawString("Signature over printed name", ReportFont, Brushes.Black, 275, 1100)
End Sub
When you use a PrintDocument, you gain a huge amount of flexibility and precision - you are in total control of what gets printed, when, and where. This makes reports appear exactly as you desire, but comes with a drawback: you have to print what you want, where you want it - you can't use controls to print tabulated data, and you are responsible for making sure that you print the right information on the right page: you get PrintPage event for each page in turn until you tell it there are no more pages.
This can get complicated, but this should help: How To Print a Data Grid in C# and .NET
[^]
The code is in C#, but it's well explained and there are online converters to more primitive languages: Code Converter[^]Please, follow this link: Printing Reports in Windows Forms[^]. There you'll find a way how to print data in tabular format.