0

Hi,

Im trying to transfer some text from the richTextBox into an existing MS word template at a specific location.
I am able to transfer text to any location i like, but i want to retain the formatting of the text from the richTextBox.

Im trying to copy the text to the clipboard, and pasting it in Word, but its not working for some reason.

Microsoft.Office.Interop.Word.Selection sel = oWord.Selection;
Clipboard.Clear();                    
//richTextBox4.SelectAll();
Clipboard.SetDataObject(richTextBox4.Rtf, true);                        
                    
IDataObject data = Clipboard.GetDataObject();                    
sel.InsertBefore(data.GetData(DataFormats.Rtf).ToString());

Can anyone tell me how to fix this, or is there any other way to transfer a chunk of text from richTextBox to MS Word without loosing the formatting.
please note: i know i can directly save data from richTextBox to an rtf or doc file.. i want to insert the data in an existing template.

thanks!

Edited by jatin24: n/a

2
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by jatin24
0

Hello.
I was playing with your code. Here's what I've got:

// selecting some text in RichTextBox
...
Clipboard.SetText(richTextBox1.SelectedRtf, TextDataFormat.Rtf);
sel.Paste();
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.