-
Jul 20th, 2006, 08:11 AM
#1
Thread Starter
Hyperactive Member
How to convert HTML Table to text file?
Hello Everybody,
Can someone tell me if it is possible to convert html table to text file?
the table in the text file will look something like that:
VB Code:
========================================
| |
| | | | | | | | ========================================
imagine there are cells in it...
Best Regards,
ERAN
Eran Fox
ASSEMBLER,C,C++,VB6,SQL...
-
Jul 20th, 2006, 08:18 AM
#2
Re: How to convert HTML Table to text file?
yes it is possible, but you will have to format the cells with spaces and/or tabs
pete
-
Jul 20th, 2006, 08:56 AM
#3
Re: How to convert HTML Table to text file?
ok.. here is a sample
new project
add a reference to the Microsoft HTML Object Library
add a textbox (Kinda big)
make it multiline
i created a simple table in an html doc..
VB Code:
Private Sub Command1_Click()
Dim HTML As HTMLDocument
Dim tHTML As New HTMLDocument
Dim TBL As HTMLTable
Dim ROW As HTMLTableRow
Dim COL As HTMLTableCol
Dim CELL As HTMLTableCell
Dim tmp As String
Set HTML = tHTML.createDocumentFromUrl("c:\table.html", vbNullString)
Do While HTML.readyState <> "complete"
DoEvents
Loop
Text1 = ""
For Each TBL In HTML.getElementsByTagName("table")
For Each ROW In TBL.rows
tmp = ""
For Each CELL In ROW.cells
tmp = tmp & "| " & Space(4) & CELL.innerText & Space(4)
Next
Text1 = Text1 & tmp & "|" & vbCrLf
Text1 = Text1 & "|" & String(Len(tmp) - 1, "=") & "|" & vbCrLf
Next
Next
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 21st, 2006, 12:37 AM
#4
Thread Starter
Hyperactive Member
Re: How to convert HTML Table to text file?
Hello Static,
Thank you for your reply,
But look at this HTML Table:
HTML Code:
<html>
<body>
<table border=5 cellspacing=1 cellpadding=2>
<tr align=center>
<td>this is a simple cell width</td><td>2</td><td>3</td><td>4</td>
</tr>
<tr align=center>
<td colspan=2>this cells width is like 2 simple cells</td><td>3</td><td>4</td>
</tr>
<tr align=center>
<td colspan=3>this cells width is like 3 simple cells</td><td>4</td>
</tr>
<tr align=center>
<td colspan=4>this cells width is like 4 simple cells</td>
</tr>
<tr align=center>
<td colspan=4 bgcolor=silver><hr size=3 width=300></td>
</tr>
<tr align=center>
<td>1</td><td rowspan=2>this cells height is like 2 simple cells</td>
<td rowspan=3>this cells height is like 3 simple cells</td>
<td rowspan=4>this cells height is like 4 simple cells</td>
</tr>
<tr align=center>
<td>1</td>
</tr>
<tr align=center>
<td>1</td><td>2</td>
</tr>
<tr align=center>
<td>1</td><td>2</td><td>3</td>
</tr>
</table>
</body>
</html>
in the text box it looks like this:
| this is a simple cell width | 2 | 3 | 4 |
|=====================================================================|
| this cells width is like 2 simple cells | 3 | 4 |
|======================================================================|
| this cells width is like 3 simple cells | 4 |
|===========================================================|
| this cells width is like 4 simple cells |
|================================================|
| |
|=========|
| 1 | this cells height is like 2 simple cells | this cells height is like 3 simple cells | this cells height is like 4 simple cells |
|=================================================================================================== =============================================================|
| 1 |
|==========|
| 1 | 2 |
|=====================|
| 1 | 2 | 3 |
|================================|
Any Ideas?
ERAN
Eran Fox
ASSEMBLER,C,C++,VB6,SQL...
-
Jul 21st, 2006, 04:42 AM
#5
Re: How to convert HTML Table to text file?
you can format the text to give you table like spacing using code, for output to file the following would change
| this is a simple cell width | 2 | 3 | 4 |
to
edit: this page takes out all the extra spaces, so i can't show here
though it does not look right on this page
VB Code:
mytest = " | this is a simple cell width | 2 | 3 | 4 |"
arrfi = Split(mytest, "|")
li = Len(arrfi(1))
clist = arrfi(1)
For i = 2 To UBound(arrfi) - 1
If Len(arrfi(i)) > li Then li = Len(arrfi(i)): clist = arrfi(i)
Next
Open "test.txt" For Output As 1
For i = 1 To UBound(arrfi) - 1
If Len(arrfi(i)) < li Then
myind = Space((Len(clist) - Len(arrfi(i))) / 2)
arrfi(i) = myind & arrfi(i) & myind
End If
Next
Print #1, Join(arrfi, "|")
Close 1
for the output to look correct in a text box, you would have to use textwidth to work out the number of spaces for that particular font.
you would also need to work out how it will fit in the width of your textbox., it might be easier to print it to a form or picturebox
pete
Last edited by westconn1; Jul 21st, 2006 at 04:45 AM.
-
Jul 21st, 2006, 07:19 AM
#6
Re: How to convert HTML Table to text file?
oh, i forgot to say change the font to COurier New or another Fixed Width FOnt...
but.. ok, so it needs some work... lemme see what I can figure out.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 21st, 2006, 08:38 AM
#7
Thread Starter
Hyperactive Member
Re: How to convert HTML Table to text file?
Hello Again,
The problem will always be the blanks...
if i'll know the numer of blanks then i will know how many "spaces" to add to every cell...
I tried the courier new but no luck...
Thank you both,
ERAN
Eran Fox
ASSEMBLER,C,C++,VB6,SQL...
-
Jul 21st, 2006, 09:06 AM
#8
Re: How to convert HTML Table to text file?
well this was closer... but I cant get it quite right.. and I can get the rowspan ones to work...
sorry..
VB Code:
Private Sub Command1_Click()
Dim HTML As HTMLDocument
Dim tHTML As New HTMLDocument
Dim TBL As HTMLTable
Dim ROW As HTMLTableRow
Dim COL As HTMLTableCol
Dim CELL As HTMLTableCell
Dim tmp As String
Dim LongLen As Integer
Dim iSPC As Integer
Set HTML = tHTML.createDocumentFromUrl("c:\table.html", vbNullString)
Do While HTML.readyState <> "complete"
DoEvents
Loop
Text1 = ""
For Each TBL In HTML.getElementsByTagName("table")
For Each ROW In TBL.rows
For Each CELL In ROW.cells
If LongLen < Len(CELL.innerText) Then LongLen = Len(CELL.innerText)
Next
Next
Next
For Each TBL In HTML.getElementsByTagName("table")
For Each ROW In TBL.rows
tmp = ""
For Each CELL In ROW.cells
iSPC = ((LongLen * CELL.colSpan) - Len(CELL.innerText)) / 2
iSPC = iSPC + ((CELL.colSpan - 1) * 1)
tmp = tmp & "|" & Space(iSPC) & CELL.innerText & Space(iSPC)
Next
Text1 = Text1 & tmp & "|" & vbCrLf
Text1 = Text1 & "|" & String(Len(tmp) - 1, "=") & "|" & vbCrLf
Next
Next
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 21st, 2006, 02:44 PM
#9
Thread Starter
Hyperactive Member
Re: How to convert HTML Table to text file?
Hello Static,
Thank you for your Time and Efforts,
I think this is a very hard thing to do but it is possible - just need to figure it out.
Thank you a LOT!!!
If you'll have a new idea i will be happy to hear from you,
Best Regards,
ERAN
Eran Fox
ASSEMBLER,C,C++,VB6,SQL...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|