Solved

how to insert html into a wordDoc Openxml

Posted on 2011-02-22
5
1,077 Views
Last Modified: 2012-05-11
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().Text = "<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

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

Open in new window

0
Comment
Question by:xav056
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:Hairbrush
ID: 34961381
Hi Xav

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.
0
 
LVL 9

Author Comment

by:xav056
ID: 34963479
this uss vba or com,
I am looking for ways to do this using the openxml sdk, without a word com object
Thank you
0
 
LVL 9

Accepted Solution

by:
xav056 earned 0 total points
ID: 34971708
using ltchunck seems to be the solution
0
 
LVL 12

Expert Comment

by:Hairbrush
ID: 34977777
Thanks for sharing the solution altChunk - I've learned something new!
0
 
LVL 9

Author Closing Comment

by:xav056
ID: 35005244
this seems to be the solution I am looking for, found it myself
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with error in Query 2 31
ASP.NET (VB) return a record 2 38
Input parameteres to DragOver 2 20
MYSQL responding very slow 3 23
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question