Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Reading Rich Text into Microsoft Office 2007 using VSTO

Posted on 2009-04-29
Medium Priority
Last Modified: 2013-11-10
I am developing C#.Net application in which Rich Text is created in one of several several Rich Text Edit boxes in the application. I am also using Visual Studio Tools for Office in order to Programmatically add the Rich Text content into a Microsoft Office document in various locations.  My problem is that I have not been able to get the Rich Text read in preserving the formatting.  I have tried using a ContentControl and setting the Type = WdContentControlType.wdContentControlRichText, but the Word Document only interprets it as raw text.  Should I be using some other technique?

I'm really not even sure how to read text into the ContentControl.  I have tried using a Range, but maybe that's not the correct way.

I am using C#.Net with Visual Studio 2008 and Microsoft.Office.Core and Microsoft.Office.Interop.Word.
Question by:thomehm
  • 2
LVL 23

Accepted Solution

irudyk earned 750 total points
ID: 24324618
You could take a look at the following MS KB - http://support.microsoft.com/kb/258513 which describes how to create an RTF string, copy the RTF string to the clipboard, and then paste the RTF string into the document.  You could convert the VB code that is there into C# and modify it so that the text is copied into the content control rather than the Word document itself.

Author Comment

ID: 24428678
I am using the Clipboard to insert the Rich Text, my code is a little simpler and different:

                    Clipboard.SetData(DataFormats.Rtf, strDescription);
                    RowCurrent.Cells[defs.ICIName + 1].Range.Paste();

It seems to work for me.
LVL 23

Expert Comment

ID: 24431680
Glad to hear that you came up with something that worked...thanks for posting the code (I agree, your code is much simpler)!

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
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.

581 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