Replacing text in a Word document with RTF

R

Richard Berg

Hey,
I've got the following problem:
I have a Word document that I use as a template. In it I want to
replace any occurances of "[TEXT]" with the formated text that is
entered into a RichTextBox (I'm using c#). I load a Word.Document, get
a Range and a Find and then use Find.Execute to replace text. The
problem is that [TEXT] gets replaced with a string that represents the
entered RTF with rtf codes (like
"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1053{\\fonttbl{\\f0\\fnil\\fcharset0
Times New Roman;}}\n\\viewkind4\\uc1\\pard\\b\\f0\\fs24
dasddas\\b0\\par\n\\par\nafasf\\par\nreerre\\par\n}\n\r\n\r\n{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1053{\\fonttbl{\\f0\\fnil\\fcharset0
Times New Roman;}}\n\\viewkind4\\uc1\\pard\\b\\f0\\fs24
dasddas\\b0\\par\n\\par\nafasf\\par\nreerre\\par\n}\n\r\n\r\n")
instead of the real text ("dasddas afasf reerre" in Times new roman
with first word in bold).
Is there any way to insert the text into the document with correct
formating?
Thanks!
 
C

Cindy M -WordMVP-

Hi Richard,

The only way Word can convert RichText to formatted Word text is by opening or inserting a file (thus triggering a converter), or when
pasting from the Clipboard.

there is no way to insert RTF text into Word and have it convert to Word formatting.

Possibly, if you're automating Word 2003, you could transform the RTF into WordProcessingML (Word's XML); that can be assigned directly to a
Word range.
I have a Word document that I use as a template. In it I want to
replace any occurances of "[TEXT]" with the formated text that is
entered into a RichTextBox (I'm using c#). I load a Word.Document, get
a Range and a Find and then use Find.Execute to replace text. The
problem is that [TEXT] gets replaced with a string that represents the
entered RTF with rtf codes (like
"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1053{\\fonttbl{\\f0\\fnil\\fcharset0
Times New Roman;}}\n\\viewkind4\\uc1\\pard\\b\\f0\\fs24
dasddas\\b0\\par\n\\par\nafasf\\par\nreerre\\par\n}\n\r\n\r\n{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1053{\\fonttbl{\\f0\\fnil\\fcharset0
Times New Roman;}}\n\\viewkind4\\uc1\\pard\\b\\f0\\fs24
dasddas\\b0\\par\n\\par\nafasf\\par\nreerre\\par\n}\n\r\n\r\n")
instead of the real text ("dasddas afasf reerre" in Times new roman
with first word in bold).
Is there any way to insert the text into the document with correct
formating?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :)
 
P

Perico

Don't know if this will help, but I remember reading in my O'Reilly VB
Controls book that the rtftextbox contral has a vb property for writing out
the formatting, or alternatively, writing out the value of the control.
Perhaps there is something in C#?
 

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