Solved

export HTML table to excel

Posted on 2002-05-01
6
487 Views
Last Modified: 2007-11-27
Hi there,
 I need to export a dynamically created table in HTML to a MS Excel file. This is a clientside application,
and I can only use VBscript or javascript. It does NOT have a server! so I cannot use asp and jsp technologies.
I need a way to export whatever you see on the screen into a excel or CSV file. Any ideas??
0
Comment
Question by:sandloper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:n_narayanan
ID: 6985043
0
 
LVL 3

Expert Comment

by:n_narayanan
ID: 6985071
Sorry the above is for EXCEL TO HTML

The below is the Japanese Site which does HTML2EXCELL

http://hp.vector.co.jp/authors/VA014833/Excel/HTML2XL.html

Narayanan
0
 
LVL 3

Accepted Solution

by:
n_narayanan earned 200 total points
ID: 6985073
I am appending the code taken from the above site,

Option Explicit

'*********************************************************************
' HTML2Excel/Directory2Excel Ver 2.0
'
' HTML L TABLE p Excel L[NV[gIG]]\7
' HTML2Excel M HTML6I
\\ji TABLE L`epG]]\7
' Directory2Excel MfB Ng
LS HTML6pN[I5\7
'
'Designed for HPCF http://www.hpcf.com/
'by poetlabo http://www.bekkoame.ne.jp/%7Epoetlabo/
'also available at http://www.vector.co.jp/authors/VA014833/
'Copyleft:1999, p 6 poetlabo@cap.bekkoame.ne.jp
'lRL       BH-      |OEpEzz7i1Fp
= }5\7
'*********************************************************************

Sub HTML2Excel2()
    Dim file_name As String
   
    file_name = Application.GetOpenFilename("HTML6 (*.htm),*.htm")
    If file_name = "False" Then Exit Sub
   
    Call GetTABLE(file_name)
   
    Application.StatusBar = "HTML^Opm5D"\7B"
    Call ReplaceTags("<*>", "")  '// HTML^Om
    Call ReplaceTags("&nbsp;", "")   '// s6m
    Call ReplaceTags("&amp;", "&")     '// & L
    Call ReplaceTags("&lt;", "<")     '// ,Hh
    Call ReplaceTags("&gt;", ">")     '// eHh
    Call ReplaceTags(Chr(9), "")   '// ^u6m
    Application.StatusBar = False
    Beep
    MsgBox file_name & "L`epG]]\5=B", 0, "HTML2Excel"
End Sub

Sub GetTABLE(file_name As String)
    Const TABLEstag As String = "<TABLE"
    Const TABLEetag As String = "</TABLE>"
    Const tagc As String = ">"
    Dim FileNum As Integer
    Dim TRn As String, TextLine As String
    Dim TABLEstart As Integer, TABLEend As Integer

    Application.StatusBar = "HTMLt@C p
J"D"\7B"

    FileNum = FreeFile()
    Open file_name For Input Access Read As #FileNum
   
    On Error GoTo CloseFile

    Do Until EOF(FileNum)
        Line Input #FileNum, TextLine
        TRn = TRn & TextLine
    Loop
   
    TABLEstart = 1
    TABLEstart = InStr(TABLEstart, TRn, TABLEstag, 1)
    If TABLEstart = 0 Then
        Application.StatusBar = False
        MsgBox Title:="E+\9qE5=B", _
            prompt:=file_name & " :" & Chr(13) & Chr(10) & _
            "1Lt@C IMA\L`e* )=h\9qB"
        Exit Sub
    End If
    Application.StatusBar = "TABLEL`epG]qE"\7B*Imi\E(R?->3"B"
    Do
        TABLEstart = InStr(TABLEstart, TRn, tagc, 1) + 1
        TABLEend = InStr(TABLEstart, TRn, TABLEetag, 1)
        TextLine = Mid(TRn, TABLEstart, TABLEend - TABLEstart)
        Call GetTRs(TextLine)
        TABLEstart = TABLEend + 8
        TABLEstart = InStr(TABLEstart, TRn, TABLEstag, 1)
    Loop Until TABLEstart = 0

CloseFile:
    Application.StatusBar = False
    Close #FileNum
End Sub

Sub GetTRs(TRn As String)
    Const TRstag As String = "<TR", tagc As String = ">"
    Const Msg1 As String = "f ", Msg2 As String = " spG]qE"\7B"
    Dim TextLine As String
    Dim TRstart As Integer, TRend As Integer, TABLEend As Integer
    Dim rn As Integer
   
    TRstart = InStr(1, TRn, TRstag, 1)
    Do Until TRstart = 0
        TRstart = InStr(TRstart, TRn, tagc, 1) + 1
        TRend = InStr(TRstart, TRn, TRstag, 1)
        TextLine = Mid(TRn, TRstart, TRend - TRstart)
        rn = rn + 1
        Application.StatusBar = Msg1 & rn & Msg2
        Call GetTHsTDs(TextLine, rn)
        TRstart = TRend
    Loop
    TextLine = Mid(TRn, TRstart, Len(TRn) - TRstart)
    rn = rn + 1
    Application.StatusBar = Msg1 & rn & Msg2
    Call GetTHsTDs(TextLine, rn)
End Sub

Sub GetTHsTDs(TextLine As String, rn As Integer)
    Const tagc As String = ">"
    Dim Cstart As Integer, Cend As Integer
    Dim StrArray() As String, cn As Integer
   
    Cstart = GetTHTDstart(1, TextLine)
    Cstart = InStr(Cstart, TextLine, tagc, 1) + 1
    Cend = GetTHTDstart(Cstart, TextLine)
    Do While Cend > 0
        cn = cn + 1
        ReDim Preserve StrArray(1 To cn)
        StrArray(cn) = Mid(TextLine, Cstart, Cend - Cstart)
        Cstart = InStr(Cend, TextLine, tagc, 1) + 1
        Cend = GetTHTDstart(Cstart, TextLine)
    Loop
    cn = cn + 1
    ReDim Preserve StrArray(1 To cn)
    StrArray(cn) = Mid(TextLine, Cstart, Len(TextLine) - Cstart + 1)
    Range(Cells(rn, 1), Cells(rn, cn)).Value = StrArray()
End Sub

Function GetTHTDstart(Cstart As Integer, TextLine As String) As Integer
    Const THstag As String = "<TH", TDstag As String = "<TD", tagc As String = ">"
    Dim THstart As Integer, TDstart As Integer

    THstart = InStr(Cstart, TextLine, THstag, 1)
    TDstart = InStr(Cstart, TextLine, TDstag, 1)
    GetTHTDstart = Application.Min(THstart, TDstart)
    If GetTHTDstart = 0 Then GetTHTDstart = Application.Max(THstart, TDstart)
End Function


Cheers

Narayanan
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6986815
optionally, you could take a look at:
www.angelfire.com/realm/vb-shared/index.html under specific topic
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7698700
Hi sandloper,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: n_narayanan and Richie_Simonetti

sandloper, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7755546
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

Richie_Simonetti points added to:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20463716.html
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question