Solved

how to insert html into a wordDoc Openxml

Posted on 2011-02-22
5
1,069 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SqlDataBase 7 48
Can I use VBA in Word to make a Table AutoFit to contents? 7 38
Datagridview column when exported to Excel changes vb.net 1 13
Hey!!!! 1 22
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

810 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