|
|
Title | Display FlexGrid data in an HTML table |
Keywords | FlexGrid, sort, grid, HTML, Web |
Categories | Controls, Utilities, Internet |
|
|
Loop through the rows creating <TR> ... </TR> entries. For each row, loop through the columns creating <TD> ... </TD> entries.
|
|
Private Sub cmdShowHtml_Click()
Dim txt As String
Dim r As Integer
Dim c As Integer
Dim fname As String
Dim fnum As Integer
' Make an HTML string for the grid data.
txt = "<TABLE BORDER=1 BGCOLOR=#00C0FF CELLPADDING=5>" _
& vbCrLf
' Display the first row as a header.
txt = txt & "<TR>" & vbCrLf
For c = 0 To MSFlexGrid1.Cols - 1
txt = txt & " <TH>" & MSFlexGrid1.TextMatrix(0, c) _
& "</TH>" & vbCrLf
Next c
txt = txt & "</TR>" & vbCrLf
' Display the rest of the rows.
For r = 1 To MSFlexGrid1.Rows - 1
txt = txt & "<TR>" & vbCrLf
For c = 0 To MSFlexGrid1.Cols - 1
txt = txt & " <TD>" & _
MSFlexGrid1.TextMatrix(r, c) & "</TD>" & _
vbCrLf
Next c
txt = txt & "</TR>" & vbCrLf
Next r
txt = "<HTML><HEAD></HEAD><BODY>" & vbCrLf & _
txt & "</BODY></HTML>"
' Save the text into a file.
fname = App.Path
If Right$(fname, 1) <> "\" Then fname = fname & "\"
fname = fname & "temp.htm"
fnum = FreeFile
Open fname For Output As fnum
Print #fnum, txt
Close fnum
' Display the file.
ShellExecute hwnd, "open", fname, vbNullString, _
vbNullString, SW_SHOW
End Sub
|
|
This example also sorts the FlexGrid's columns.
|
|
|
|
|
|