VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Converting the Excel(xls) file in to corresponding HTML Tables

by Karthick (2 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Sun 23rd April 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Converting the Excel(xls) file in to corresponding HTML Tables

API Declarations


Dim rs As New ADODB.Recordset


Rate Converting the Excel(xls) file in to corresponding HTML Tables



Dim fnum As Integer
Dim num_fields As Integer
Dim i As Integer
Dim num_processed As Integer

    fnum = FreeFile
    Open Text2.Text For Output As fnum

    Print #fnum, "<HTML>"
    Print #fnum, "<HEAD>"
    Print #fnum, "<TITLE>Convert Excel to HTML</TITLE>"
    Print #fnum, "</HEAD>"

    Print #fnum, "<TABLE ALIGN=CENTER WIDTH =100% CELLPADDING=2 CELLSPACING=2  BORDER=1>"

    con.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\karthik\testfiles\bctest.xls;Extended Properties=Excel 8.0;Persist Security Info=False")
    Set rs = con.Execute("select * from [bctest$]")

    Print #fnum, " <TR BGCOLOR=#green>"
    num_fields = rs.Fields.Count
    For i = 0 To num_fields - 1
        Print #fnum, " <TH>";
        Print #fnum, rs.Fields(i).Name;
        Print #fnum, "</TH>"
    Next i
    Print #fnum, "</TR>"
 
    Do While Not rs.EOF
        num_processed = num_processed + 1
        Print #fnum, "<TR BGCOLOR=#99CCCC>";
        For i = 0 To num_fields - 1
            Print #fnum, "<TD>";
            Print #fnum, rs.Fields(i).Value;
            Print #fnum, "</TD>"
        Next i
        Print #fnum, "</TR>";

        rs.MoveNext
    Loop
    Print #fnum, "</TABLE>"
    
    Print #fnum, "<P>"
    Print #fnum, "<center>"
    Print #fnum, "<H3>" & _
        Format$(num_processed) & _
        " records displayed.</H3>"
  
    Print #fnum, "<h1><I><FONT COLOR= RED> THIS IS THE HTML FILE</font></I><h1>"
    Print #fnum, "</BODY>"
    Print #fnum, "</HTML>"
 
    rs.Close
    con.Close
    Close fnum
    MsgBox "Processed " & Format$(num_processed) & " records."

    Exit Sub

End Sub

Private Sub Form_Load()
    Text1.Text = "D:\karthik\testfiles\bctest.xls"
    Text2.Text = "D:\karthik\testfiles\bctest.htm"
End Sub

Download this snippet    Add to My Saved Code

Converting the Excel(xls) file in to corresponding HTML Tables Comments

No comments have been posted about Converting the Excel(xls) file in to corresponding HTML Tables. Why not be the first to post a comment about Converting the Excel(xls) file in to corresponding HTML Tables.

Post your comment

Subject:
Message:
0/1000 characters