Vignesh071498
asked on
Print the contents of MSFlex grid
Hi,
How can I print out the contents of a MSFlex Grid control
Thanks,
V
How can I print out the contents of a MSFlex Grid control
Thanks,
V
ASKER
Hi Dabellei,
This doesn't seem to work. All that gets printed is a long series of numbers corresponding to the row & col nums. Any other suggestions
V
This doesn't seem to work. All that gets printed is a long series of numbers corresponding to the row & col nums. Any other suggestions
V
That's for sure if you look at the first part of the code i fill in the grid with those number so what's print is what's inside the cells.
If you fill the grid with anything else like letter they will be print.
Now every cell is print on a different line because i use the print command for every cell if you want to print on the same line use ; after the print command.
For x = 0 To 4
MSFlexGrid1.Row = x
For y = 0 To 4
MSFlexGrid1.Co l = y
MSFlexGrid1.Te xt = chr$(65+x+y)
Next y
Next x
This code will fill the cell with letter instead of number.
If you fill the grid with anything else like letter they will be print.
Now every cell is print on a different line because i use the print command for every cell if you want to print on the same line use ; after the print command.
For x = 0 To 4
MSFlexGrid1.Row = x
For y = 0 To 4
MSFlexGrid1.Co
MSFlexGrid1.Te
Next y
Next x
This code will fill the cell with letter instead of number.
Use this function wich print a traditional Grid. You could modify it. (if you modify it, please send me the code, it could be useful for me : waty.thierry@usa.net). It resizes the font ... :
Sub GridPrint(Grid As Control, szTitle As String, bLines As Integer)
' *** Print a grid control ***
Dim nRow As Long
Dim nCol As Long
Dim sCurrentX As Single
Dim sCurrentY As Single
Dim sMaxLine As Single
Dim nPage As Integer
Dim szPage As String
Dim sOldY As Single
Dim sPageWidth As Single
Dim sBeginLeft As Single
Dim sBeginGrid As Single
If (Grid.Rows = 0) Then Exit Sub
' *** We look for the maximum size for the fontsize ***
sMaxLine = 99999999
' *** By default, we set the fontsize of the grid ***
Printer.FontSize = Grid.FontSize
' *** Here is the maximum width of the page
sPageWidth = Printer.Width * 0.94 - 200
' *** We calculate the maximum possible fontsize ***
Do While (sMaxLine > sPageWidth) And (Printer.FontSize > 0)
sMaxLine = 0
For nCol = 0 To Grid.Cols - 1
sMaxLine = sMaxLine + (Printer.FontSize / Grid.FontSize) * Grid.ColWidth(nCol)
Next
' *** We change the fontsiz if needed ***
If (sMaxLine > sPageWidth) Then Printer.FontSize = Printer.FontSize - 1
Loop
' *** We begin on page 1 ***
nPage = 1
' *** We put The title ***
' *** and the headers of each column ***
GoSub PRINT_HEADERS
For nRow = 1 To Grid.Rows - 1
If (bLines = True) Then Printer.Line (sBeginLeft, sCurrentY)-(sMaxLine, sCurrentY)
' *** We print on a new page if needed ***
If (sCurrentY >= Printer.Height * 0.93 - Printer.TextHeight("A")) Then
If (bLines = True) Then
' *** Bottom line
Printer.Line (sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)-(s MaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)
' *** Left line ***
Printer.Line (sBeginLeft, sBeginGrid)-(sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)
' *** Right line ***
Printer.Line (sMaxLine, sBeginGrid)-(sMaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)
End If
Printer.NewPage
nPage = nPage + 1
' *** We put The title ***
' *** and the headers of each column ***
GoSub PRINT_HEADERS
End If
sCurrentX = 4 * Printer.TwipsPerPixelX
For nCol = 0 To Grid.Cols - 1
If (nCol > 0) Then
sCurrentX = sCurrentX + (Printer.FontSize / Grid.FontSize) * Grid.ColWidth(nCol - 1)
If bLines = True Then Printer.Line (sCurrentX - 4 * Printer.TwipsPerPixelX, sBeginGrid)-(sCurrentX - 4 * Printer.TwipsPerPixelX, Printer.CurrentY + (Printer.TextHeight("A") / 2) - 4 * Printer.TwipsPerPixelY)
End If
' *** Print cell text ***
Grid.Col = nCol
Grid.Row = nRow
Printer.CurrentX = sCurrentX
Printer.CurrentY = sCurrentY + (Printer.TextHeight("A") / 2)
Printer.Print Grid.Text
Next
sCurrentY = sCurrentY + (Printer.TextHeight("A") * 2)
Next
If (bLines = True) Then
' *** Bottom line
Printer.Line (sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)-(s MaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)
' *** Left line ***
Printer.Line (sBeginLeft, sBeginGrid)-(sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)
' *** Right line ***
Printer.Line (sMaxLine, sBeginGrid)-(sMaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)
End If
Printer.EndDoc
Exit Sub
PRINT_HEADERS:
' *** We print the title ***
sCurrentY = Printer.CurrentY
Printer.FontBold = True
Printer.Print szTitle
Printer.FontBold = False
Printer.Print ""
' *** We print the page number on the first line ***
sOldY = Printer.CurrentY
szPage = "Page " & CStr(nPage)
Printer.FontItalic = True
Printer.CurrentX = sPageWidth - Printer.TextWidth(szPage)
Printer.CurrentY = sCurrentY
Printer.Print szPage
Printer.FontItalic = False
Printer.CurrentY = sOldY
' *** We print the grid ***
Printer.CurrentY = Printer.CurrentY + (Printer.TextHeight("A"))
sCurrentY = Printer.CurrentY
sBeginGrid = sCurrentY
sBeginLeft = 0
sCurrentX = 4 * Printer.TwipsPerPixelX
' *** We print the header of each column ***
If (bLines = True) Then Printer.Line (sBeginLeft, sCurrentY)-(sMaxLine, sCurrentY)
Printer.Print
sCurrentY = Printer.CurrentY + (Printer.TextHeight("A") / 2)
For nCol = 0 To Grid.Cols - 1
If (nCol > 0) Then sCurrentX = sCurrentX + (Printer.FontSize / Grid.FontSize) * Grid.ColWidth(nCol - 1)
' *** Print cell text ***
Grid.Col = nCol
Grid.Row = 0
Printer.CurrentX = sCurrentX
Printer.CurrentY = sCurrentY
Printer.Print Grid.Text
Next
sCurrentY = sCurrentY + (Printer.TextHeight("A") * 1.5)
Printer.Print
If (bLines = True) Then Printer.Line (sBeginLeft, sCurrentY)-(sMaxLine, sCurrentY)
Return
End Sub
Sub GridPrint(Grid As Control, szTitle As String, bLines As Integer)
' *** Print a grid control ***
Dim nRow As Long
Dim nCol As Long
Dim sCurrentX As Single
Dim sCurrentY As Single
Dim sMaxLine As Single
Dim nPage As Integer
Dim szPage As String
Dim sOldY As Single
Dim sPageWidth As Single
Dim sBeginLeft As Single
Dim sBeginGrid As Single
If (Grid.Rows = 0) Then Exit Sub
' *** We look for the maximum size for the fontsize ***
sMaxLine = 99999999
' *** By default, we set the fontsize of the grid ***
Printer.FontSize = Grid.FontSize
' *** Here is the maximum width of the page
sPageWidth = Printer.Width * 0.94 - 200
' *** We calculate the maximum possible fontsize ***
Do While (sMaxLine > sPageWidth) And (Printer.FontSize > 0)
sMaxLine = 0
For nCol = 0 To Grid.Cols - 1
sMaxLine = sMaxLine + (Printer.FontSize / Grid.FontSize) * Grid.ColWidth(nCol)
Next
' *** We change the fontsiz if needed ***
If (sMaxLine > sPageWidth) Then Printer.FontSize = Printer.FontSize - 1
Loop
' *** We begin on page 1 ***
nPage = 1
' *** We put The title ***
' *** and the headers of each column ***
GoSub PRINT_HEADERS
For nRow = 1 To Grid.Rows - 1
If (bLines = True) Then Printer.Line (sBeginLeft, sCurrentY)-(sMaxLine, sCurrentY)
' *** We print on a new page if needed ***
If (sCurrentY >= Printer.Height * 0.93 - Printer.TextHeight("A")) Then
If (bLines = True) Then
' *** Bottom line
Printer.Line (sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)-(s
' *** Left line ***
Printer.Line (sBeginLeft, sBeginGrid)-(sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)
' *** Right line ***
Printer.Line (sMaxLine, sBeginGrid)-(sMaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)
End If
Printer.NewPage
nPage = nPage + 1
' *** We put The title ***
' *** and the headers of each column ***
GoSub PRINT_HEADERS
End If
sCurrentX = 4 * Printer.TwipsPerPixelX
For nCol = 0 To Grid.Cols - 1
If (nCol > 0) Then
sCurrentX = sCurrentX + (Printer.FontSize / Grid.FontSize) * Grid.ColWidth(nCol - 1)
If bLines = True Then Printer.Line (sCurrentX - 4 * Printer.TwipsPerPixelX, sBeginGrid)-(sCurrentX - 4 * Printer.TwipsPerPixelX, Printer.CurrentY + (Printer.TextHeight("A") / 2) - 4 * Printer.TwipsPerPixelY)
End If
' *** Print cell text ***
Grid.Col = nCol
Grid.Row = nRow
Printer.CurrentX = sCurrentX
Printer.CurrentY = sCurrentY + (Printer.TextHeight("A") / 2)
Printer.Print Grid.Text
Next
sCurrentY = sCurrentY + (Printer.TextHeight("A") * 2)
Next
If (bLines = True) Then
' *** Bottom line
Printer.Line (sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)-(s
' *** Left line ***
Printer.Line (sBeginLeft, sBeginGrid)-(sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)
' *** Right line ***
Printer.Line (sMaxLine, sBeginGrid)-(sMaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)
End If
Printer.EndDoc
Exit Sub
PRINT_HEADERS:
' *** We print the title ***
sCurrentY = Printer.CurrentY
Printer.FontBold = True
Printer.Print szTitle
Printer.FontBold = False
Printer.Print ""
' *** We print the page number on the first line ***
sOldY = Printer.CurrentY
szPage = "Page " & CStr(nPage)
Printer.FontItalic = True
Printer.CurrentX = sPageWidth - Printer.TextWidth(szPage)
Printer.CurrentY = sCurrentY
Printer.Print szPage
Printer.FontItalic = False
Printer.CurrentY = sOldY
' *** We print the grid ***
Printer.CurrentY = Printer.CurrentY + (Printer.TextHeight("A"))
sCurrentY = Printer.CurrentY
sBeginGrid = sCurrentY
sBeginLeft = 0
sCurrentX = 4 * Printer.TwipsPerPixelX
' *** We print the header of each column ***
If (bLines = True) Then Printer.Line (sBeginLeft, sCurrentY)-(sMaxLine, sCurrentY)
Printer.Print
sCurrentY = Printer.CurrentY + (Printer.TextHeight("A") / 2)
For nCol = 0 To Grid.Cols - 1
If (nCol > 0) Then sCurrentX = sCurrentX + (Printer.FontSize / Grid.FontSize) * Grid.ColWidth(nCol - 1)
' *** Print cell text ***
Grid.Col = nCol
Grid.Row = 0
Printer.CurrentX = sCurrentX
Printer.CurrentY = sCurrentY
Printer.Print Grid.Text
Next
sCurrentY = sCurrentY + (Printer.TextHeight("A") * 1.5)
Printer.Print
If (bLines = True) Then Printer.Line (sBeginLeft, sCurrentY)-(sMaxLine, sCurrentY)
Return
End Sub
Do you agree my question?
ASKER
This doesn't work.
It works with grid. You have to modify it for use with msFlexGrid.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
MSFlexGrid1.Cols = 5
For x = 0 To 4
MSFlexGrid1.Row = x
For y = 0 To 4
MSFlexGrid1.Col = y
MSFlexGrid1.Text = Str$(x) & Str(y)
Next y
Next x
For x = 0 To 4
MSFlexGrid1.Row = x
For y = 0 To 4
MSFlexGrid1.Col = y
Printer.Print MSFlexGrid1.Text
Next y
Next x
Printer.EndDoc