Is there a way to easily convert html to wordml?

D

DarrylR

I Googled this topic last night and discovered that many people have
encountered this problem. However, I didn't find any references to an easy
solution (or, oddly enough, a product). I'm trying to do it from a VSTO
solution created in C# .NET using the primary interop assemblies.

I'm attempting to translate html that incorporates standard formatting tags
(e.g. <b/>,<u/>,<i/>,<sub>,and <sup>), lists (e.g. ul), etc. to something
that can be inserted using the InsertXML method (similar to the code found
at http://blogs.officezealot.com/chris/archive/2003/11/06/1253.aspx below).

Original Sub:
Private Sub InsertWordML()
Dim sXML As String
sXML = "<wordDocument
xmlns='http://schemas.microsoft.com/office/word/2003/wordml'><body>" & _
"<p><r><t xml:space='preserve'>Example of WordML and InsertXML
run at </t></r>" & _
"</p><p/><p/></body></wordDocument>"
'Insert WordML
Selection.InsertXML (sXML)
End Sub

What I'd like to do:
Private Sub InsertWordML()
Dim sXML As String
sXML = "<wordDocument
xmlns='http://schemas.microsoft.com/office/word/2003/wordml'
xmlns:ht='http://www.w3.org/TR/REC-html40'>" &_
"<body><p><r><t xml:space='preserve'><ht:u>Example <ht:b>of
WordML</ht:b> and InsertXML</ht:u></t></r>" &_
"</p><p/><p/></body></wordDocument>"
'Insert WordML
Selection.InsertXML (sXML)
End Sub

I found some references to SpreadsheetML accepting HTML using the following
syntax:
<ss:Data ss:Type='String'
xmlns='http://www.w3.org/TR/REC-html40'>hi<U>there</U> everyone</ss:Data>.

Is there a WordML equivalent syntax?

Thanks in advance,
Darryl R.
 
D

DarrylR

I ended up using the Range.InsertFile method for now. It means writing an
html file to disk temporarily, but I found that it's not too expensive in
terms off performance.

Regards,
Darryl R.
 

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