麻烦大家给个例子做做参考~谢谢~该程序要打包的哦

解决方案 »

  1.   

    用me.PrintForm最简单,但是只能打印可以显示出来的部分,而且遇上针式打印机会慢的要死。
    用Pirnter.Line Printer.Print一个格子一个格子慢慢画也行,就是麻烦
    或者用Rectangle DrawText等API一个格子一个格子慢慢画,同样麻烦,而且API与Printer对象同时使用可能出现莫明其妙的问题,好处是处理单元格对齐很灵活
    N久前写的程序,贴半个函数,大概看两眼吧,别字细看,看头晕了别赖我,嘿嘿
    Public Sub PrintExport(Grid As MSFlexGrid, ColRightPos() As Long, Danwei As String, ID As String)
        Dim i As Long, j As Long, P As Long
        Dim ColLeftPos As Long
        Dim TopRowOfPage As Long, CurTopPos As Long
        Dim IsNewPage As Boolean
        Dim DrawRc As RECT, TestRc As RECT, LineRc As RECT
        Dim S As String
        
        Printer.PaperSize = vbPRPSA4
        Printer.FontName = "宋体"
        Printer.FontSize = 9
        Printer.FontBold = False
        Printer.PrintQuality = vbPRPQHigh
        Printer.FontTransparent = True
        If (Grid.Rows - 1) Mod LinesPerPage = 0 Then
            PageCount = (Grid.Rows - 1) \ LinesPerPage
        Else
            PageCount = ((Grid.Rows - 1) \ LinesPerPage) + 1
        End If
        
        MinRowHeight = 350# / Printer.TwipsPerPixelY
        FixRowSpaceTop = 1700# / Printer.TwipsPerPixelX
        SpaceLeft = 1000# / Printer.TwipsPerPixelX
        SpaceBottom = 1500# / Printer.TwipsPerPixelX
        SpaceTop = FixRowSpaceTop + MinRowHeight '2100# / Printer.TwipsPerPixelX
        IsNewPage = True
    ''    TopRowOfPage = 1
        
        With Grid
            For P = 0 To .Cols - 1
                ColRightPos(P) = ColRightPos(P) + SpaceLeft
            Next
            For i = 1 To .Rows - 2
                If IsNewPage Then
                    
                    TopRowOfPage = i
                    
                    Printer.Print " "
                    Printer.DrawWidth = 3
                    Printer.Print " "
                    If .Rows - TopRowOfPage > LinesPerPage Then
                        Rectangle Printer.hdc, SpaceLeft, FixRowSpaceTop, ColRightPos(P - 1), SpaceTop + MinRowHeight * LinesPerPage
                    Else
                        Rectangle Printer.hdc, SpaceLeft, FixRowSpaceTop, ColRightPos(P - 1), SpaceTop + MinRowHeight * (.Rows - TopRowOfPage)
                    End If
                    Printer.DrawWidth = 1
                    
                    
                    CurPage = CurPage + 1
                    Call DrawTitle(Danwei, ID)
                    ColLeftPos = SpaceLeft
                    OldFontSize = Printer.FontSize
                    OldFontBold = Printer.FontBold
                    Printer.FontSize = 11
                    Printer.FontBold = True
                    Printer.Print "   "
                    For j = 0 To .Cols - 1
                        DrawRc.Left = ColLeftPos + 2
                        DrawRc.Right = ColRightPos(j) - 2
                        DrawRc.Top = FixRowSpaceTop
                        DrawRc.Bottom = DrawRc.Top + MinRowHeight
                        TestRc = DrawRc
                        S = .TextMatrix(0, j)
                        DrawText Printer.hdc, S, -1, TestRc, DT_CALCRECT Or DT_NOPREFIX Or DT_CENTER
                        If TestRc.Bottom < DrawRc.Bottom Then
                            DrawRc.Top = DrawRc.Top + (DrawRc.Bottom - TestRc.Bottom) \ 2
                        End If
    ''''                    Debug.Print DrawRc.Left, DrawRc.Right
                        Rectangle Printer.hdc, ColLeftPos, FixRowSpaceTop, ColRightPos(j), FixRowSpaceTop + MinRowHeight
                        DrawText Printer.hdc, S, -1, DrawRc, DT_NOPREFIX Or DT_CENTER
                        ColLeftPos = ColRightPos(j)
                    Next
                    Printer.FontSize = OldFontSize
                    Printer.FontBold = OldFontBold
                    Printer.Print "   "
                End If
                ColLeftPos = SpaceLeft
                CurTopPos = (i - TopRowOfPage) * MinRowHeight + SpaceTop
                For j = 0 To .Cols - 1
                    DrawRc.Left = ColLeftPos + 2
                    DrawRc.Right = ColRightPos(j) - 2
                    DrawRc.Top = CurTopPos
                    DrawRc.Bottom = DrawRc.Top + MinRowHeight
                    TestRc = DrawRc
                    LineRc = DrawRc
                    
                    S = .TextMatrix(i, j)
                    Rectangle Printer.hdc, LineRc.Left - 2, LineRc.Top, LineRc.Right + 2, LineRc.Bottom
                    If j = 3 Or j = 5 Then
                        S = Format(S, "¥0.00")
                        DrawText Printer.hdc, S, -1, TestRc, DT_CALCRECT Or DT_NOPREFIX Or DT_RIGHT
                        If TestRc.Bottom < DrawRc.Bottom Then
                            DrawRc.Top = DrawRc.Top + (DrawRc.Bottom - TestRc.Bottom) \ 2
                        End If
                        DrawRc.Right = DrawRc.Right - 60# / Printer.TwipsPerPixelX
                        DrawText Printer.hdc, S, -1, DrawRc, DT_NOPREFIX Or DT_RIGHT
                    Else
                        DrawText Printer.hdc, S, -1, TestRc, DT_CALCRECT Or DT_CENTER
                        If TestRc.Bottom < DrawRc.Bottom Then
                            DrawRc.Top = DrawRc.Top + (DrawRc.Bottom - TestRc.Bottom) \ 2
                        End If
                        
                        If TestRc.Right > DrawRc.Right Then
                            DrawText Printer.hdc, S, -1, DrawRc, DT_NOPREFIX Or DT_LEFT
                        Else
                            DrawText Printer.hdc, S, -1, DrawRc, DT_NOPREFIX Or DT_CENTER
                        End If
                    End If                ColLeftPos = ColRightPos(j)
                Next
                
                If (i Mod LinesPerPage) = 0 Then
                    Printer.NewPage
                    IsNewPage = True
                Else
                    IsNewPage = False
                End If
            Next
        End With
      

  2.   

    把MSFGIRD的数据集导出到EXCEL文件,再打印呀