locked
Convert HTML Page to DBF RRS feed

  • Question

  • I want to Convert HTML File into DBF without using MS Office..



    Please "Mark as Answer" if this post answered your question. :)

    Kalpesh Chhatrala | Software Developer | Rajkot | India

    Kalpesh's Blog
    Wednesday, November 4, 2009 9:29 AM
    Answerer

Answers

  • I think you mean to convert table(s) in an HTML to a cursor/dbf. You don't need Office to do such a processing. You can use document processing. ie:

    Local loExplorer, loTables, ix
    Set Textmerge To Memvar m.lcHTML Additive Noshow
    Set Textmerge On
    \<html><body>
    \Sample HTML With Tables In it.
    \
    Use (_samples+'data\customer')
    \<table>
    	\<tr>
    For ix=1 To Fcount()
    		\<th><< TRIM(FIELD(m.ix)) >></th>
    Endfor
    	\</tr>
    Scan
    	\<tr>
    	For ix=1 To Fcount()
    	    \<td><< Evaluate(Field(m.ix)) >></td>
    	Endfor
    	\</tr>
    Endscan
    \</table>
    
    Use (_samples+'data\orders')
    \<table>
    	\<tr>
    For ix=1 To 5
    		\<th><< TRIM(FIELD(m.ix)) >></th>
    Endfor
    	\</tr>
    Scan While Recno()<200
    	\<tr>
    	For ix=1 To 5
    		\<td><< EVALUATE(FIELD(m.ix)) >></td>
    	Endfor
    	\</tr>
    Endscan
    \</table>
    \</body></html>
    Set Textmerge To
    Set Textmerge Off
    
    CLOSE DATABASES all
    
    loExplorer = Createobject('Xplorer')
    loExplorer.LoadHTML(m.lcHTML)
    
    loTables = loExplorer.Document.getElementsByTagName('TABLE')
    For ix=0 To loTables.Length-1
    	HTMLTableToCursor(loTables.Item(m.ix),m.ix)
    Endfor
    
    Procedure HTMLTableToCursor(toTable,tnTableNo)
    	Local loRows,loRow,loHeaders,loHeader,loCells,loCell,ix,jx,lcXML
    	loRows    = toTable.Rows
    	loHeaders = loRows.Item(0)
    	Set Textmerge To Memvar lcXML Noshow
    	Set Textmerge On
    \\<data>
    	For ix=1 To loRows.Length-1
    		loRow = loRows.Item[m.ix]
    \<row
    		For jx=0 To loHeaders.Cells.Length-1
    			loHeader = loHeaders.Cells.Item(m.jx)
    			loCell   = loRow.Cells.Item(m.jx)
    \\ <<TRIM(m.loHeader.innerText)>>="<<TRIM(loCell.innerHTML)>>"
    		Endfor
    \/>
    	Endfor
    \\</data>
    	Set Textmerge To
    	Set Textmerge Off
    	Xmltocursor(m.lcXML,'HTMLCursor'+Padl(m.tnTableNo,3,'0'))
    Endproc
    
    Define Class XPlorer As Form
    	Add Object html As OleControl With OleClass='Shell.Explorer'
    	Document=Null
    	Procedure Init
    		This.html.Navigate2('about:blank')
    	Endproc
    	Procedure html.Refresh
    		Nodefault
    	Endproc
    	Procedure LoadHTML(tcHtml)
    		This.html.Document.Write(m.tcHtml)
    		This.Document = This.html.Document
    	Endproc
    Enddefine
    


    Friday, November 13, 2009 7:33 PM

All replies

  • I want to Convert HTML File into DBF without using MS Office..
    Please "Mark as Answer" if this post answered your question. :)

    Kalpesh Chhatrala | Software Developer | Rajkot | India

    Kalpesh's Blog
    Friday, November 13, 2009 12:56 PM
    Answerer
  • I think you mean to convert table(s) in an HTML to a cursor/dbf. You don't need Office to do such a processing. You can use document processing. ie:

    Local loExplorer, loTables, ix
    Set Textmerge To Memvar m.lcHTML Additive Noshow
    Set Textmerge On
    \<html><body>
    \Sample HTML With Tables In it.
    \
    Use (_samples+'data\customer')
    \<table>
    	\<tr>
    For ix=1 To Fcount()
    		\<th><< TRIM(FIELD(m.ix)) >></th>
    Endfor
    	\</tr>
    Scan
    	\<tr>
    	For ix=1 To Fcount()
    	    \<td><< Evaluate(Field(m.ix)) >></td>
    	Endfor
    	\</tr>
    Endscan
    \</table>
    
    Use (_samples+'data\orders')
    \<table>
    	\<tr>
    For ix=1 To 5
    		\<th><< TRIM(FIELD(m.ix)) >></th>
    Endfor
    	\</tr>
    Scan While Recno()<200
    	\<tr>
    	For ix=1 To 5
    		\<td><< EVALUATE(FIELD(m.ix)) >></td>
    	Endfor
    	\</tr>
    Endscan
    \</table>
    \</body></html>
    Set Textmerge To
    Set Textmerge Off
    
    CLOSE DATABASES all
    
    loExplorer = Createobject('Xplorer')
    loExplorer.LoadHTML(m.lcHTML)
    
    loTables = loExplorer.Document.getElementsByTagName('TABLE')
    For ix=0 To loTables.Length-1
    	HTMLTableToCursor(loTables.Item(m.ix),m.ix)
    Endfor
    
    Procedure HTMLTableToCursor(toTable,tnTableNo)
    	Local loRows,loRow,loHeaders,loHeader,loCells,loCell,ix,jx,lcXML
    	loRows    = toTable.Rows
    	loHeaders = loRows.Item(0)
    	Set Textmerge To Memvar lcXML Noshow
    	Set Textmerge On
    \\<data>
    	For ix=1 To loRows.Length-1
    		loRow = loRows.Item[m.ix]
    \<row
    		For jx=0 To loHeaders.Cells.Length-1
    			loHeader = loHeaders.Cells.Item(m.jx)
    			loCell   = loRow.Cells.Item(m.jx)
    \\ <<TRIM(m.loHeader.innerText)>>="<<TRIM(loCell.innerHTML)>>"
    		Endfor
    \/>
    	Endfor
    \\</data>
    	Set Textmerge To
    	Set Textmerge Off
    	Xmltocursor(m.lcXML,'HTMLCursor'+Padl(m.tnTableNo,3,'0'))
    Endproc
    
    Define Class XPlorer As Form
    	Add Object html As OleControl With OleClass='Shell.Explorer'
    	Document=Null
    	Procedure Init
    		This.html.Navigate2('about:blank')
    	Endproc
    	Procedure html.Refresh
    		Nodefault
    	Endproc
    	Procedure LoadHTML(tcHtml)
    		This.html.Document.Write(m.tcHtml)
    		This.Document = This.html.Document
    	Endproc
    Enddefine
    


    Friday, November 13, 2009 7:33 PM