Printing Word Warpped Flexi Grid Columns
I know how to print flexi grid data, but I am having problems if it is warped. After reading previous posts I wrote my own code to print the rows and columns. But it does not print warped columns properly. Example....
Grid Data:
-------------------------------------------------------------------------------
This text | Column 2 | Column 3 |
will Warp | | |
-------------------------------------------------------------------------------
I want printing to be.....
-------------------------------------------------------------------------------
This text Column 2 Column 3
will Warp
-------------------------------------------------------------------------------
But I get.....
-------------------------------------------------------------------------------
This text will Warp Column 2 Column 3
-------------------------------------------------------------------------------
My Code:
Code:
Dim Rows As Integer
Dim Cols As Integer
Dim X() As Integer
Dim Y() As Integer
Dim LastX As Integer
Dim LastY As Integer
Dim MaxWidth() As Integer
Dim MaxHeight() As Integer
Private Sub printGrid()
Dim tempWidth As Long
Dim Pages As Integer
Dim Copy As Integer
Dim pCnt As Integer
Dim Copies() As Integer
Printer.Font = grdReport.CellFontName
Printer.FontSize = grdReport.CellFontSize
With grdReport
ReDim X(.Cols)
ReDim Y(.Rows)
ReDim MaxWidth(.Cols)
ReDim MaxHeight(.Rows)
X(1) = PD.LBorder
Y(1) = PD.TBorder
For Rows = 1 To (.Rows - 1)
For Cols = 1 To (.Cols - 1)
If CInt(Printer.TextWidth(grdReport.TextMatrix(Rows, Cols))) > MaxWidth(Cols) Then MaxWidth(Cols) = CInt(Printer.TextWidth(grdReport.TextMatrix(Rows, Cols)))
If CInt(Printer.TextHeight(grdReport.TextMatrix(Rows, Cols))) > MaxHeight(Rows) Then MaxHeight(Rows) = CInt(Printer.TextHeight(grdReport.TextMatrix(Rows, Cols)))
Next Cols
Next Rows
For Cnt = 1 To (grdReport.Cols - 1)
If (tempWidth + (MaxWidth(Cnt) + PD.CellWSpacing)) > (Printer.ScaleWidth - PD.LBorder - PD.RBorder) Then
tempWidth = (MaxWidth(Cnt) + PD.CellWSpacing)
Pages = Pages + 1
Else
tempWidth = tempWidth + (MaxWidth(Cnt) + PD.CellWSpacing)
End If
Next Cnt
ReDim Copies(Pages + 1)
Pages = 0
tempWidth = 0
For Cnt = 1 To (grdReport.Cols - 1)
If (tempWidth + (MaxWidth(Cnt) + PD.CellWSpacing)) > (Printer.ScaleWidth - PD.LBorder - PD.RBorder) Then
tempWidth = (MaxWidth(Cnt) + PD.CellWSpacing)
Pages = Pages + 1
Copies(Pages) = (Cnt - Copies(Pages - 1))
Else
tempWidth = tempWidth + (MaxWidth(Cnt) + PD.CellWSpacing)
End If
Next Cnt
Copy = 0
For pCnt = 1 To Pages
Copy = Copy + Copies(pCnt)
Next pCnt
Copies(Pages + 1) = (grdReport.Cols - Copy - 1)
On Error GoTo Err
For Cnt = 0 To Pages
For Rows = 1 To (.Rows - 1)
For Cols = 1 To (Copies(Cnt + 1))
Copy = 0
For pCnt = 1 To Cnt
Copy = Copy + Copies(pCnt)
Next pCnt
If X(Cols + Copy) = 0 And (Cols + Copy) <> 0 Then
X(Cols + Copy) = LastX + PD.CellWSpacing + MaxWidth((Cols - 1) + Copy)
End If
Printer.CurrentX = X(Cols + Copy)
Printer.CurrentY = Y(Rows)
LastX = Printer.CurrentX
LastY = Printer.CurrentY
Printer.Print grdReport.TextMatrix(Rows, (Cols + Copy))
Next Cols
Y(Rows + 1) = Y(Rows) + MaxHeight(Rows) + PD.CellHSpacing
If (Y(Rows + 1) + MaxHeight(Rows)) > Printer.ScaleHeight Then
Y(Rows + 1) = PD.TBorder
Printer.NewPage
End If
Next Rows
Debug.Assert False
If Cnt = Pages Then Exit For
X(Cols + Copy) = PD.LBorder
Y(0) = PD.TBorder
LastX = 0
LastY = 0
Printer.NewPage
Next Cnt
End With
Printer.EndDoc
Exit Sub
Err:
If Err.Number = 482 Then MsgBox "There was a Printer Error in printing the Data", vbOKOnly + vbExclamation, "Printer Error"
End Sub
-------------------------------------------------------------------------------
There might be some flaws in the code due to my experience level. (I know 1 place). Any way I would appreciate if you help me.
The MSH Flexi Grid Control is name 'grdReport' and Command Button as 'cmdReport'