打印本文 打印本文 关闭窗口 关闭窗口
vsprint打印实例
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1389  更新时间:2009/4/23 16:37:43  文章录入:mintao  责任编辑:mintao

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
        ''''重新设置行的位置为第一条记录
        rst.MoveFirst
        ''''设置总的页面数
        If Rows <= 18 Then ''''总行数小于等于页面显示的总行数
            pages = 1
            iCurrenrows = Rows
            iLastrows = 0
        Else ''''总行数大于页面显示的总行数
            If Rows Mod 18 = 0 Then ''''总行数等于页面显示的总行数倍数
                pages = Int(Rows / 18)
                iLastrows = 0
            Else ''''总行数不等于页面显示的总行数倍数
                pages = Int(Rows / 18) + 1
                iLastrows = Rows Mod 18
            End If
            iCurrenrows = 18
        End If
        iPage = 1 ''''设置当前页面为第一页面
        iRow = 0 ''''设置当前行位置为空
        ''''
        With printCtl
            .Orientation = orLandscape ''''设置横向打印
            .TableBorder = tbAll
            ''''设置页面四边的边距
            .MarginTop = 1400
            .MarginBottom = 1400
            .MarginLeft = 1400
            .MarginRight = 1400
            ''''设置字体名字
''''*************************************开始打印文档的内容*************************************            .StartDoc
            .StartDoc
            .TablePen = 20
            For iPage = 1 To pages
                 ''''设置标题
                .FontSize = 14
                .FontBold = True
                .TextAlign = taCenterMiddle
                .Paragraph = str_title
                .Paragraph = ""
                .FontBold = False
                .FontSize = 10
                ''''设置页面表格
                .FontSize = 9
                .StartTable
                .TextAlign = taRightMiddle
                .Paragraph = "单位: 元"
                .StartTable
                .TableCell(tcCols) = cols
                If iPage = pages And iLastrows <> 0 Then
                    Trows = iLastrows + 2
                Else
                     Trows = iCurrenrows + 2
                End If
                .TableCell(tcRows) = Trows
                ''''///
                .TableCell(tcRowHeight) = 400
                .TableCell(tcColWidth, , 1) = 600
                .TableCell(tcColWidth, , 2) = 2600
                .TableCell(tcColWidth, , 3) = 1000
                .TableCell(tcColWidth, , 4) = 1000
                .TableCell(tcColWidth, , 5) = 1000
                .TableCell(tcColWidth, , 6) = 1000
                .TableCell(tcColWidth, , 7) = 1000
                .TableCell(tcColWidth, , 8) = 1000
                .TableCell(tcColWidth, , 9) = 1000
                .TableCell(tcColWidth, , 10) = 1000
                .TableCell(tcColWidth, , 11) = 1000
                .TableCell(tcColWidth, , 12) = 1000
                .TableCell(tcColWidth, , 13) = 1000
                .Table

[1] [2]  下一页

打印本文 打印本文 关闭窗口 关闭窗口