关于我想用VB打印格式不同不规则的,含数据库记录的表格,谁有现成的相关的源码,我在这先谢谢了!的问题
VB下数据报表打印输出方法有多种,一是通过自己的设计和编程完成报表打印输出。二是通过MS OFFICE实现报表打印输出。三是应用数据报表设计器的报表打印输出。本人经常使用第一种方法,它具有根据需要灵活应用的特点,但需编写程序。下附代码,第一段代码定义基本变量,第二段代码定义打印函数,第三段代码是具体打印代码,含数据转换。
第四段代码是窗体加载代码,具体连接数据库和打印代码根据你所涉及的数据要求进行修改。
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
‘确定页数
k = Int(zsl / 80)’80为每页行数
If k – zsl / 80 80 Then
Printer。
Line (500, 695 + 180 * 80)-(10000, 695 + 180 * 80)
Printer。NewPage
End If
Next p
Printer。EndDoc ‘ 打印完成。
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。备件代码,cs。备件名称,cs。备件规格,cs。进口计算机号,cs。最低库存量,sl。结存数量,sl。结存金额,sl。结存单价,sl。类别代码 from JWCK_BM as cs,jwl_jiec as sl” & _
” where cs。
备件代码 = sl。备件代码” & ” and cs。备件代码>” & “”” & ” order by sl。类别代码,sl。备件代码”
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(结存金额) as hj from jwl_jiec”
Adodc3。Refresh
End Sub
以上供参考。其它请参考西安交通大学出版社出版的“VISUAL BASIC 6。
0 高级编程技巧-ADO数据访问篇“
。