We iterate through the table data adding rows and columns as we
go.
Every time we add a row, we check to see whether we've reached
the end of the page. When we get there, we check the last row we
added to ensure that it wasn't truncated. If it was, then we delete
it and prepare to insert it again. We add a new page, prepare to
draw the table headers again and reset the row framing and row
shading parameters.
We insert all our content into the current row, cell by cell.
After we've inserted all our content into the row, we select it and
add a frame or background shading as appropriate. Finally, we save
the document.
theFrame = True
theShade = False
theRows = Split(theText, vbCrLf)
i = 0
Do
' add in new row - see if it fitted onto page
If theTable.NextRow = False Then
' delete and draw last row again?
If theTable.RowTruncated Then
theTable.DeleteLastRow
i = i - 1
End If
' insert headers
i = i - 1
If i >= 0 Then theRows(i) =
theRows(0)
' frame row and reset shading
theFrame = True
theShade = False
' add new page to table
theDoc.Flatten
theTable.NewPage
End If
' get next row
If i < 0 Or i > UBound(theRows) Then Exit Do
theRow = theRows(i)
i = i + 1
' add all the cells into a row
theCols = Split(theRow, vbTab)
For j = 0 To UBound(theCols)
theTable.NextCell
theTable.AddText theCols(j)
Next
' underline first row & shade every other row
theTable.SelectRow theTable.Row
If theFrame = True Then theTable.Frame False, True,
False, False
If theShade Then theTable.Fill "200 200 220"
theFrame = False
theShade = Not theShade
Loop
theDoc.Flatten
theDoc.Save "c:\mypdfs\table2.pdf"
|