Imprimir contenido de msflexgrid

jorge
04 de Febrero del 2003
como puedo imprimir los datos que muestro en un msflexgrid?

Alex Cardona
04 de Febrero del 2003
Option Explicit

Private Sub Form_Click()
' Add sample data to the grid
Dim i, j
For i = 0 To Grid1.Cols - 1
For j = 0 To Grid1.Rows - 1
Grid1.Col = i
Grid1.Row = j
Grid1.Text = Format$(i + j + i ^ j)
Next
Next
' Print the data
Call Grid_Print(Grid1)
Printer.EndDoc

End Sub

Sub Grid_Print(Grid As Control)
Dim tppx As Integer ' alias TwipsPerPixelX
Dim tppy As Integer ' alias TwipsPerPixelY
tppx = Printer.TwipsPerPixelX
tppy = Printer.TwipsPerPixelY
Dim Col As Integer ' index to grid columns
Dim Row As Integer ' index to grid rows
Dim x0 As Single ' upper left corner
Dim y0 As Single ' "
Dim x1 As Single ' position of text
Dim y1 As Single ' "
Dim x2 As Single ' position of grid lines
Dim y2 As Single ' "

' set upper left corner
x0 = Printer.CurrentX
y0 = Printer.CurrentY

' draw the border around the grid
If Grid.BorderStyle <> 0 Then
Printer.Line -Step(Grid.Width - tppx, Grid.Height - tppy), , B
x0 = x0 + tppx
y0 = y0 + tppy
End If

' draw the text in the grid
x1 = x0
For Col = 0 To Grid.Cols - 1
' skip non-visible columns
If Col >= Grid.FixedCols And Col < Grid.LeftCol Then
Col = Grid.LeftCol
End If
' stop if outside grid
If x1 + Grid.ColWidth(Col) >= Grid.Width Then Exit For
y1 = y0
For Row = 0 To Grid.Rows - 1
' skip non-visible columns
If Row >= Grid.FixedRows And Row < Grid.TopRow Then
Row = Grid.TopRow
End If
' stop if outside grid
If y1 + Grid.RowHeight(Row) >= Grid.Height Then Exit For
' set position to print the cell
Printer.CurrentX = x1 + tppx * 2
Printer.CurrentY = y1 + tppy
' print cell text
Grid.Col = Col
Grid.Row = Row
Printer.Print Grid.Text
' advance to next row
y1 = y1 + Grid.RowHeight(Row)
If Grid.GridLines Then
y1 = y1 + tppy
End If
Next
' advance to next column
x1 = x1 + Grid.ColWidth(Col)
If Grid.GridLines Then
x1 = x1 + tppx
End If
Next

' draw grid lines
If Grid.GridLines Then
x2 = x0
y2 = y0
For Col = 0 To Grid.Cols - 1
' skip non-visible columns
If Col >= Grid.FixedCols And Col < Grid.LeftCol Then
Col = Grid.LeftCol
End If
x2 = x2 + Grid.ColWidth(Col)
' stop if outside grid
If x2 >= Grid.Width Then Exit For
Printer.Line (x2, y0)-Step(0, y1 - tppy)
x2 = x2 + tppx
Next
For Row = 0 To Grid.Rows - 1
' skip non-visible rows
If Row >= Grid.FixedRows And Row < Grid.TopRow Then
Row = Grid.TopRow
End If
y2 = y2 + Grid.RowHeight(Row)
' stop if outside grid
If y2 >= Grid.Height Then Exit For
Printer.Line (x0, y2)-Step(x1 - tppx, 0)
y2 = y2 + tppy
Next
End If
End Sub


Alex Cardona
04 de Febrero del 2003
Option Explicit

Private Sub Form_Click()
' Add sample data to the grid
Dim i, j
For i = 0 To Grid1.Cols - 1
For j = 0 To Grid1.Rows - 1
Grid1.Col = i
Grid1.Row = j
Grid1.Text = Format$(i + j + i ^ j)
Next
Next
' Print the data
Call Grid_Print(Grid1)
Printer.EndDoc

End Sub

Sub Grid_Print(Grid As Control)
Dim tppx As Integer ' alias TwipsPerPixelX
Dim tppy As Integer ' alias TwipsPerPixelY
tppx = Printer.TwipsPerPixelX
tppy = Printer.TwipsPerPixelY
Dim Col As Integer ' index to grid columns
Dim Row As Integer ' index to grid rows
Dim x0 As Single ' upper left corner
Dim y0 As Single ' "
Dim x1 As Single ' position of text
Dim y1 As Single ' "
Dim x2 As Single ' position of grid lines
Dim y2 As Single ' "

' set upper left corner
x0 = Printer.CurrentX
y0 = Printer.CurrentY

' draw the border around the grid
If Grid.BorderStyle <> 0 Then
Printer.Line -Step(Grid.Width - tppx, Grid.Height - tppy), , B
x0 = x0 + tppx
y0 = y0 + tppy
End If

' draw the text in the grid
x1 = x0
For Col = 0 To Grid.Cols - 1
' skip non-visible columns
If Col >= Grid.FixedCols And Col < Grid.LeftCol Then
Col = Grid.LeftCol
End If
' stop if outside grid
If x1 + Grid.ColWidth(Col) >= Grid.Width Then Exit For
y1 = y0
For Row = 0 To Grid.Rows - 1
' skip non-visible columns
If Row >= Grid.FixedRows And Row < Grid.TopRow Then
Row = Grid.TopRow
End If
' stop if outside grid
If y1 + Grid.RowHeight(Row) >= Grid.Height Then Exit For
' set position to print the cell
Printer.CurrentX = x1 + tppx * 2
Printer.CurrentY = y1 + tppy
' print cell text
Grid.Col = Col
Grid.Row = Row
Printer.Print Grid.Text
' advance to next row
y1 = y1 + Grid.RowHeight(Row)
If Grid.GridLines Then
y1 = y1 + tppy
End If
Next
' advance to next column
x1 = x1 + Grid.ColWidth(Col)
If Grid.GridLines Then
x1 = x1 + tppx
End If
Next

' draw grid lines
If Grid.GridLines Then
x2 = x0
y2 = y0
For Col = 0 To Grid.Cols - 1
' skip non-visible columns
If Col >= Grid.FixedCols And Col < Grid.LeftCol Then
Col = Grid.LeftCol
End If
x2 = x2 + Grid.ColWidth(Col)
' stop if outside grid
If x2 >= Grid.Width Then Exit For
Printer.Line (x2, y0)-Step(0, y1 - tppy)
x2 = x2 + tppx
Next
For Row = 0 To Grid.Rows - 1
' skip non-visible rows
If Row >= Grid.FixedRows And Row < Grid.TopRow Then
Row = Grid.TopRow
End If
y2 = y2 + Grid.RowHeight(Row)
' stop if outside grid
If y2 >= Grid.Height Then Exit For
Printer.Line (x0, y2)-Step(x1 - tppx, 0)
y2 = y2 + tppy
Next
End If
End Sub