Help re Converting Word Table Cell Contents to HTML

C

Craig Petrie

Hi,
My client has a large table in Word 2003 that has formatted text in the
cells and I need to read and convert each cells formatted contents to simple
html(no wordML) via vb.net code. The formatting contains: bold, italic,
superscript & subscript text, bullet points.

I have looked up many sites on the web and also searched in user groups but
have not yet seen a way to code the above in vb.net 2003. In my VB.net app I
currently open and read the word table and output all cell contents into an
XML structure OK but this strips out any formatting - I just need to know
how to read and convert the formatted text inside a single cell to html
format in vb.net.

Can anyone suggest tools/components or code or examples that would help me
do this.

I am using VB.net 2003 and Office Professional Edition 2003.

cheers,
Craig, New Zealand
 
P

Peter Hewett

Hi Craig Petrie

What about copying the table to a new Word document then saving that document as Filtered
HTML?

HTH + Cheers - Peter (NZ)
 
S

skube

Craig, I am trying to do the same thing with VB.NET. Would you be
willing to share your code? I am new to VB programming and I'm trying
to do the exact same thing. Although I am trying to output to XML
rather than HTML. I've found Russell Jones's article
(http://www.devx.com/dotnet/Article/17358?trk=DXRSS_XML) helpful in
getting started.

However, I can't figure out a few things (like I said, I'm new to VB):
1) How to find all the Word Styles being used in the Word doc?
2) How do I read specific Word table cells?
3) Is it possible to read specific Word table columns?

Any info/comments/suggestions would be most appreciated and helpful.

thanks,
Sean
 
P

Peter Hewett

Hi skube

Here the answers to the questions you asked. I've provided VBA samples since the .Net port
is a no brainer:

Public Sub StylesInUse()
Dim styItem As Word.Style

For Each styItem In ActiveDocument.Styles
If styItem.InUse Then
' The style is being used
End If
Next
End Sub

Public Sub TableCells()
Dim celItem As Word.Cell

' Use the first table in the document
With ActiveDocument.Tables(1)
.Cell(1, 1) = "Add some text"
.Cell(3, 4) = .Cell(1, 1)
End With
End Sub

Public Sub UseTableColumns()
Dim celItem As Word.Cell

' Use the first table in the document
With ActiveDocument
For Each celItem In .Tables(1)
MsgBox celItem.Range.Text
Next
End With
End Sub

Be very careful when referring to a tables Columns or Rows property. If the table
contains merged Columns the Columns property access will fail, likewise if the table
contains merged Rows the Rows property access will fail.

Also you may be using VB.Net but that does not prevent you from using the VBA help on the
Word object model. All the above is available through Words VBA online help. Likewise
use Visual Studios object explorer to delve into the Word object model.

HTH + Cheers - Peter


(e-mail address removed) (skube), said:
 
S

skube

Peter, thanks for your reply.

I do however, have some questions...

In Sub TableCells(), you declare celItem, but don't seem to use it
anywhere. Am I missing something?

In the Sub UseTableColumns(), it seems to me that you are simply
cycling through each cell and not referring to a specific column at
all. I'm confused as to why it's even called UseTableColumns.

Thanks for the tip about the online help. It is very useful.
 
P

Peter Hewett

Hi skube

In the TableCells procedure I just declared a variable of the correct type in case you
wanted to use it. In UseTableColumns I pasted the procedure but inadvertently deleted the
end of the line:
For Each celItem In .Tables(1)

should read:
For Each celItem In .Tables(1).Columns

Cheers - Peter


(e-mail address removed) (skube), said:
Peter, thanks for your reply.

I do however, have some questions...

In Sub TableCells(), you declare celItem, but don't seem to use it
anywhere. Am I missing something?

In the Sub UseTableColumns(), it seems to me that you are simply
cycling through each cell and not referring to a specific column at
all. I'm confused as to why it's even called UseTableColumns.

Thanks for the tip about the online help. It is very useful.

HTH + Cheers - Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top