Exporting to an HTML File
Overview
You can export a cell, a block of cells, a column, a row, or an entire sheet to an HTML file. Data and property settings are translated into HTML as explained in HTML File Export Reference.
You can also export discontiguous cells, blocks of cells, columns, and rows by performing one of the following actions:
-
Hide the cells you do not want to export
The ExportToHTML and ExportRangeToHTML methods do not export hidden rows and columns.
-
Append the cells, block of cells, columns, or rows to the first cell, block of cells, column, or row you export.
The ExportRangeToHTML method has an AppendFlag parameter. The first time you call the method, set the AppendFlag parameter to FALSE. For each succeeding method call, set the AppendFlag parameter to TRUE until all the cells, blocks of cells, columns, or rows you want to add have been added.
For example, assume your sheet has 15 rows and you want to export only the subtotals of your sheet (rows 5, 10, and 15) to an HTML file. You could use the following code to hide all rows except the subtotal rows and then export rows 5, 10, and 15.
Sub Form_Load
Dim i As Integer
Dim rc As Integer
fpSpread1.MaxRows = 15
For i = 1 to 15
fpSpread1.Row = i
If i = 5 Or i = 10 Or i = 15 Then
fpSpread1.RowHidden = False
Else
fpSpread1.RowHidden = True
End If
Next i
rc = fpSpread1.ExportToHTML("c:\subtotal.htm", 0, "c:\mylog.txt")
End Sub
You could also use the following code to append rows 10 and 15 to row 5.
SpreadExportRangeToHTML(1, 5, -1, 5, "c:\subtotal.htm", 0, "c:\mylog.txt")
SpreadExportRangeToHTML(1, 10, -1, 10, "c:\subtotal.htm", 1, "c:\mylog.txt")
SpreadExportRangeToHTML(1, 15, -1, 15, "c:\subtotal.htm", 1, "c:\mylog.txt")
When you export discontiguous cells, blocks of cells, columns, or rows,
- Data is loaded into the HTML table in the order in which it is appended.
- Appended data is placed below the previously exported data.
- If the cell is blank or the block of cells, row, or column contains blank cells, the blank cell or cells will appear in the HTML file.
- If you display the column or row headers, the headers will display for each range you export.
For example, assume you have the following data and you want to export blocks A1:B3 and D4:E5.
The code to export the blocks is:
SpreadExportRangeToHTML(1, 1, 2, 3, "c:\block.htm", 0, "c:\mylog.txt")
SpreadExportRangeToHTML(4, 4, 5, 5, "c:\block.htm", 1, "c:\mylog.txt")
The resulting HTML file would appear like this.
Notice that the blank cell E4 is exported and column and row headers display for each range that is exported. Row headers also re-number so that the row numbering sequence is correct.
Tip: After the first export, set the ColHeadersShow property to False to have subsequent exports just export the data, not the column headers. When finished, set the ColHeadersShow property to True. |
You can also use style settings from a CSS file when exporting to HTML using the ExportToHTMLEx or ExportRangeToHTMLEx methods.
By default, the file created by exporting to an HTML file has the extension .HTM; however, you can use any extension when you export from the fpSpread control or the Spread Designer.
Tip: Because you cannot import the HTML file you save back into the Spread control, you might want to save to a Spread (.SS8) file in addition to exporting it to HTML. If you want to make future modifications, you can open the Spread (.SS8) file and then resave it to HTML. |
Notes:
|