您的位置:首页 > 编程语言 > VB

vb(1) printer对象使用

2015-04-21 20:59 232 查看
Private Sub Print_网格()

  Dim RowPage As Long, ColPage As Long, RowHeight As Double, ColWidth As Double, arrRow() As Long, arrCol() As Long, i As Long, j As Long

  Const RowPageHeight As Double = 14571

  Const ColPageWidth As Double = 10773

  Const HeaderHeight As Double = 1134

  RowPage = 0

  ReDim arrRow(0) As Long

  arrRow(0) = 1

  RowHeight = msh.RowHeight(0)

  For i = 1 To msh.Rows - 1

      RowHeight = RowHeight + msh.RowHeight(i)

      If RowPage = 0 Then

         If RowHeight > (RowPageHeight - HeaderHeight) Then

            RowPage = RowPage + 1

            ReDim Preserve arrRow(UBound(arrRow) + 1) As Long

            arrRow(UBound(arrRow)) = i

            RowHeight = msh.RowHeight(i) + msh.RowHeight(0)

         End If

      Else

         If RowHeight > RowPageHeight Then

            RowPage = RowPage + 1

            ReDim Preserve arrRow(UBound(arrRow) + 1) As Long

            arrRow(UBound(arrRow)) = i

            RowHeight = msh.RowHeight(i) + msh.RowHeight(0)

         End If

      End If

  Next i

  RowPage = RowPage + 1

  ReDim Preserve arrRow(UBound(arrRow) + 1) As Long

  arrRow(UBound(arrRow)) = msh.Rows

  

  ColPage = 0

  ReDim arrCol(0) As Long

  arrCol(0) = 0

  ColWidth = 0

  For i = 0 To msh.Cols - 1

      ColWidth = ColWidth + msh.ColWidth(i)

      If ColWidth > ColPageWidth Then

         ColPage = ColPage + 1

         ReDim Preserve arrCol(UBound(arrCol) + 1) As Long

         arrCol(UBound(arrCol)) = i

         ColWidth = msh.ColWidth(i)

      End If

  Next i

  ColPage = ColPage + 1

  ReDim Preserve arrCol(UBound(arrCol) + 1) As Long

  arrCol(UBound(arrCol)) = msh.Cols

  

  For i = 1 To RowPage Step 1

      For j = 1 To ColPage Step 1

          Call Print_网格分页打印(arrRow(i - 1), arrRow(i) - 1, arrCol(j - 1), arrCol(j) - 1, i, "xxxxxx")

          Printer.NewPage

      Next j

  Next i

  Printer.EndDoc

End Sub

Private Sub Print_网格分页打印(ByVal startRow As Long, ByVal endRow As Long, ByVal startCol As Long, ByVal endCol As Long, ByVal PageNum As Long, _

                               ByVal strTitle As String)

                               

  Dim xPos As Double, yPos As Double, i As Long, j As Long

  Dim lng表格高度 As Double, lng表格宽度 As Double

   

  xPos = 567

  yPos = IIf(PageNum = 1, 2268, 1134)

  For i = startCol To endCol Step 1

      Printer.CurrentX = xPos

      Printer.CurrentY = yPos

      Printer.Print msh.TextMatrix(0, i);

      xPos = xPos + msh.ColWidth(j)

  Next i

  xPos = 567

  yPos = yPos + msh.RowHeight(0)

  For i = startRow To endRow

      Printer.CurrentY = yPos

      xPos = 567

      For j = startCol To endCol

          Printer.CurrentX = xPos

          Printer.CurrentY = yPos

          Printer.Print msh.TextMatrix(i, j);

          xPos = xPos + msh.ColWidth(j)

      Next j

      yPos = yPos + msh.RowHeight(i)

  Next i

 

  lng表格高度 = msh.RowHeight(0)

  For i = startRow To endRow Step 1

      lng表格高度 = lng表格高度 + msh.RowHeight(i)

  Next i

  lng表格宽度 = 0

  For i = startCol To endCol Step 1

      lng表格宽度 = lng表格宽度 + msh.ColWidth(i)

  Next i

  xPos = 567

  yPos = IIf(PageNum = 1, 2268, 1134)

  Printer.CurrentX = xPos

  Printer.CurrentY = yPos

  Printer.Line (xPos, yPos - 50)-(xPos + lng表格宽度, yPos - 50)

  xPos = 567

  yPos = yPos + msh.RowHeight(0)

  For i = startRow To endRow Step 1

      Printer.CurrentX = xPos

      Printer.CurrentY = yPos

      Printer.Line (xPos, yPos - 50)-(xPos + lng表格宽度, yPos - 50)

      yPos = yPos + msh.RowHeight(i)

      If i = endRow Then

         Printer.CurrentX = xPos

         Printer.CurrentY = yPos

         Printer.Line (xPos, yPos - 50)-(xPos + lng表格宽度, yPos - 50)

      End If

  Next i

  xPos = 567

  yPos = IIf(PageNum = 1, 2268, 1134)

  For i = startCol To endCol Step 1

      Printer.CurrentX = xPos

      Printer.CurrentY = yPos

      Printer.Line (xPos, yPos - 50)-(xPos, yPos + lng表格高度 - 50)

      xPos = xPos + msh.ColWidth(i)

      If i = endCol Then

         Printer.CurrentX = xPos

         Printer.CurrentY = yPos

         Printer.Line (xPos, yPos - 50)-(xPos, yPos + lng表格高度 - 50)

      End If

  Next i

  

  Printer.Line (567, 16839.9 - 600)-(11340, 16839.9 - 600)

  Printer.CurrentX = 567

  Printer.CurrentY = 16839.9 - 500

  Printer.Print "第" & PageNum & "页"

End Sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: