想請教各位﹐用Printer打印表格可以預覽﹖哪位有直接用Printer打印的公共模塊﹐可直接給標頭RS及明細部分RS,及可自動生成報表的﹐可否提供原碼參考﹐分數不限﹗

解决方案 »

  1.   

    不知道直接打印msflexgrid表格的源码是不合你心意,如果想看看,请来信:[email protected]
    分数不限 0<=分<=OO
      

  2.   

    我的郵箱是﹕[email protected],謝謝
      

  3.   

    '可以打印到图片框作为预览,obj为printer时打到打印机上。
    Sub PrintGrid(Sysname As String, Topic As String, MyGrid As Control, Name As String, Obj As Object) '打印网格
        Dim R, Step, Y, C As Integer
        
        '设置每段长度
        Step = Obj.ScaleWidth \ (MyGrid.Cols - 1 + 2)
        
        '打印页眉
        Y = Obj.CurrentY
        Obj.Line (Obj.ScaleLeft, Y + 10)-(Obj.ScaleWidth, Y + 10)
        
        '打印标题
        Y = Y + 200
        Obj.CurrentX = Obj.ScaleWidth \ 2 - LenB(Topic) * 150 \ 2
        Obj.CurrentY = Obj.CurrentY + 200
        Obj.FontSize = 14
        Obj.FontName = "楷体_GB2312"
        Obj.Print Topic
        
        '打印消费场所名称
        Y = Y + 500
        Obj.CurrentX = Obj.ScaleLeft + 500
        Obj.CurrentY = Y
        Obj.FontSize = 10
        Obj.FontName = "宋体"
        Obj.Print Trim(Sysname)
        
        '打印日期
        'Y = Y + 500
        Obj.CurrentX = Obj.ScaleLeft + 3500
        Obj.CurrentY = Y
        Obj.FontSize = 10
        Obj.FontName = "宋体"
        Obj.Print "日期:  " & Date
        
        '打印姓名
        Obj.CurrentX = Obj.ScaleWidth - 3500
        Obj.CurrentY = Y
        Obj.FontSize = 10
        Obj.FontName = "宋体"
        Obj.Print "经手人:  " & Name
        
        '打印Line
        Y = Y + 200
        Obj.Line (Obj.ScaleLeft, Y)-(Obj.ScaleWidth, Y)
        
        '打印GRIDHEADING
        Y = Y + 200
        R = 0
        For C = 0 To MyGrid.Cols - 1
            MyGrid.Row = R
            MyGrid.Col = C
            Obj.CurrentX = (Step * C) + (Step \ 2 - LenB(MyGrid.Text) * 40 \ 2)
            Obj.CurrentY = Y
            Obj.FontSize = 10
            Obj.FontName = "宋体"
            Obj.Print MyGrid.Text
        Next
        
        '打印GRID
        For R = 1 To MyGrid.Rows - 1
            If Y <= Obj.ScaleHeight - 500 Then
                Y = Y + 200
            Else
                Obj.Line (Obj.ScaleLeft, Y)-(Obj.ScaleWidth, Y)
                Y = Obj.CurrentY
                Obj.Print "'"
                Obj.Line (Obj.ScaleLeft, Y + 10)-(Obj.ScaleWidth, Y + 10)
                Y = Y + 200
            End If
            For C = 0 To MyGrid.Cols - 1
                MyGrid.Row = R
                MyGrid.Col = C
                If MyGrid.ColAlignment(C) = 7 Then
                    Obj.CurrentX = Step * (C + 1) - LenB(MyGrid.Text) * 40
                Else
                    Obj.CurrentX = (Step * C) + (Step \ 2 - LenB(MyGrid.Text) * 40 \ 2)
                End If
                Obj.CurrentY = Y
                Obj.FontSize = 10
                Obj.FontName = "宋体"
                Obj.Print MyGrid.Text
            Next
        Next
        
        '打印 Line
        Y = Y + 400
        Obj.Line (Obj.ScaleLeft, Y)-(Obj.ScaleWidth, Y)
        
        '打印 审核人
        Y = Y + 200
        Obj.CurrentX = Obj.ScaleWidth - 3000
        Obj.CurrentY = Y
        Obj.FontSize = 10
        Obj.FontName = "宋体"
        Obj.Print "审核人:"
        If TypeOf Obj Is Printer Then
            Obj.EndDoc
        End If
    End Sub
    '检测打印输出对象是不是有效
    Public Function ValidObj(objOP As Object) As Boolean
    Dim Msg As String
    If TypeOf objOP Is Form Or TypeOf objOP Is PictureBox Or TypeOf objOP Is Printer Then
    ValidObj = True
    Else
    ValidObj = False
    End If
    If Not ValidObj Then
    Msg = "无效的对象: " + vbCrLf
    Msg = Msg + vbCrLf + vbCrLf
    Msg = Msg + "有效的对象参数只能为打印机,图片框或是表单" + vbCrLf
    MsgBox Msg, vbCritical, "对象无效"
    End If
    End Function