vsprint打印实例

该博客介绍了一个使用VSPrinter控件在VB6中进行数据打印的实例,通过ADODB连接数据库获取数据,然后用Format函数格式化数据,并设置表格样式进行横向打印,每页最多显示18行数据。
摘要由CSDN通过智能技术生成

Option Explicit

Public Function formatData2(ByVal data1 As Double, ByVal data2 As Double) As String
    Dim dt1, dt2 As Double
    dt1 = data1
    dt2 = data2
    If dt1 = 0 Or dt1 = 0# Or dt2 = 0 Or dt2 = 0# Then
        formatData2 = "0.00"
    Else
        formatData2 = Format(Round(dt1 / dt2, 2), "0.00")
    End If
End Function

Public Sub print_jian_anhuizong(ByRef printCtl As VSPrinter, ByVal strTable As String, ByVal strTitle)
    Dim con As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim str_table As String
    Dim str_title As String
    Dim strSql As String
    Dim iCurrent As Integer
    Dim cols As Integer '页面表格的列数
    Dim iCurrenrows As Integer '页面表格当前显示的总行数
    Dim Rows As Long '总行数
    Dim Trows As Long '页面表格总行数
    Dim pages As Integer '总页数
    Dim iPage As Integer '当前页面
    Dim iLastrows As Integer '整页显示后剩余的行数
    Dim iRow As Long '当前行的位置
On Error GoTo err1
    str_table = strTable
    str_title = strTitle
    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strConnection & ";Persist Security Info=False"
    con.Open
    strSql = "select nn,name,unit,pricezhijiegongcheng,pricezhijie,pricerengong,pricecailiao,pricejixie," & _
            "priceqitazhijie,pricexianchang,pricejianjie,pricejihualirun,priceshuijin,priceshashijiacha ,price1 from " & str_table & " order by nn"
    rst.CursorType = adOpenKeyset
    rst.LockType = adLockOptimistic
    rst.Open strSql, con, , , adCmdText
    cols = 13
    If Not rst.BOF And Not rst.EOF Then
        '获得总的记录数rows
        rst.MoveFirst
        Do While Not rst.EOF
            Rows = Rows + 1
            rst.MoveNext
        Loop
        '重新设置行的位置为第一条记录
   

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值