xav056
asked on
how to insert html into a wordDoc Openxml
Hello
I have a word document with rich text controls with specific Title/Tags.
I would like to insert text into those controls using the openxml sdk and vb.net, however my text is html formatted lets say <b>some text </b>
If i do the following
sdtElement.Descendants(Of Text)().FirstOrDefault().T ext = "<b> some text </b>"
I see the <b></b> as text, what I would like to happen is have this text in bold.
What control should I use and How would I achieve what I want
Here's the code I am using
I have a word document with rich text controls with specific Title/Tags.
I would like to insert text into those controls using the openxml sdk and vb.net, however my text is html formatted lets say <b>some text </b>
If i do the following
sdtElement.Descendants(Of Text)().FirstOrDefault().T
I see the <b></b> as text, what I would like to happen is have this text in bold.
What control should I use and How would I achieve what I want
Here's the code I am using
Using doc As WordprocessingDocument = WordprocessingDocument.Open("C:\Test.docx", True)
Dim mainPart As MainDocumentPart = doc.MainDocumentPart()
Dim sdtElement As SdtElement = mainPart.Document.Descendants(Of SdtElement)().Where(Function(element) element.SdtProperties.GetFirstChild(Of SdtAlias)() IsNot Nothing _
AndAlso element.SdtProperties.GetFirstChild(Of SdtAlias).Val = "test").SingleOrDefault()
If sdtElement IsNot Nothing Then
sdtElement.Descendants(Of Text)().FirstOrDefault().Text = "<b> some text </b>"
End If
End Using
ASKER
this uss vba or com,
I am looking for ways to do this using the openxml sdk, without a word com object
Thank you
I am looking for ways to do this using the openxml sdk, without a word com object
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for sharing the solution altChunk - I've learned something new!
ASKER
this seems to be the solution I am looking for, found it myself
This would be one way to do it: http://www.xtremevbtalk.com/showthread.php?t=120862 but it only deals with bold and italics! Beyond that, you'd need an HTML to RTF library. There are commercial products like http://www.sautinsoft.com/products/html-to-rtf/index.php or if you Google you might find an open source library on somewhere like CodePlex.