Convert HTML Table to Excel sheet
To say the truth, we will convert HTML table to a .csv file that can be easily open with Micro$oft Excel application.
You can see my other example on how to do a "reverse thing".
First, type the URL where page containing table you want to translate, then push the button.
There is a label control that acts like a status showing progress of the job.
The resulting csv file could be found at c:\Excelfile.csv.
This code does a simple thing, you can enhance with formating, font types and so on.
To get it to work, you could download the following files:
ConvertHTMLToXls.vbp (Project file).
frmConvertToExcel.frm (Main form file).
Last addition:
The following code allows you to perform colors conversion given a HTMLColor
Value.
It will be run a little slow the first time, but subsequents calls will be fast enought.
Option Explicit
Private arr10(1 To 16) As String
Private arr30(33 To 56) As String
Public Function TransColorToXLS(HTMLColor As String) As Integer
' This code provides transformations only
' to values that Excel can understand.
Dim idx As Integer
' If array not initilized...
If arr10(1) = "" Then PopulateArr
' else...
' Locates the item in array that matches HTMLColor.
For idx = 1 To 16
If arr10(idx) = HTMLColor Then
TransColorToXLS = idx
Exit Function
End If
Next idx
For idx = 33 To 56
If arr10(idx) = HTMLColor Then
TransColorToXLS = idx
Exit Function
End If
Next idx
' if not in arrays then no color
TransColorToXLS = -4142
End Function
Public Sub PopulateArr()
arr10(1) = "#000000"
arr10(2) = "#FFFFFF"
arr10(3) = "#FF0000"
arr10(4) = "#00FF00"
arr10(5) = "#0000FF"
arr10(6) = "#FFFF00"
arr10(7) = "#FF00FF"
arr10(8) = "#00FFFF"
arr10(9) = "#800000"
arr10(10) = "#008000"
arr10(11) = "#000080"
arr10(12) = "#808000"
arr10(13) = "#800080"
arr10(14) = "#008080"
arr10(15) = "#C0C0C0"
arr10(16) = "#808080"
arr30(33) = "#00CCFF"
arr30(34) = "#CCFFFF"
arr30(35) = "#CCFFCC"
arr30(36) = "#FFFF99"
arr30(37) = "#99CCFF"
arr30(38) = "#FF99CC"
arr30(39) = "#CC99FF"
arr30(40) = "#FFCC99"
arr30(41) = "#3366FF"
arr30(42) = "#33CCCC"
arr30(43) = "#99CC00"
arr30(44) = "#FFCC00"
arr30(45) = "#FF9900"
arr30(46) = "#FF6600"
arr30(47) = "#666699"
arr30(48) = "#969696"
arr30(49) = "#003366"
arr30(50) = "#339966"
arr30(51) = "#003300"
arr30(52) = "#333300"
arr30(53) = "#993300"
arr30(54) = "#993366"
arr30(55) = "#333399"
arr30(56) = "#333333"
End Sub
Good luck!
©2001 - Richie Simonetti