Site hosted by Angelfire.com: Build your free website today!

Convert Excel sheet to HTML Table

To do things short, this code shows how you can transform an Excel Worksheet in a table in a Web page.
First, select the worksheet that you want to convert (button provided), then select where you want to save the resulting HTML page and its name (button provided, also).
For last, type the range of cells that you want to translate to.
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:

ConvertXLSToHtml.vbp (Project file).
frmConv.frm (Main form file).

Last addition:
The following code allows you to perform colors conversion given a ColorIndex 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 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

Public Function TransColorToHTML(ColorIndex As Integer) As String
Dim ColorIdx As Integer

ColorIdx = Abs(ColorIndex)
If arr10(1) = "" Then
    PopulateArr
End If
Select Case ColorIdx
Case Is < 16
    TransColorToHTML = arr10(ColorIdx)
Case Is <= 56
    TransColorToHTML = arr30(ColorIdx)
Case Is = 4142
    TransColorToHTML = ""
End Select
End Function
Good luck!

©2001 - Richie Simonetti