3
Answers

copy text from ICSharpCode.TextEditor.TexEditorControl to Word 2007

lszk

lszk

16y
7.1k
1
I'm writing a Word Add-In to hightlight the source code.
I have colored the text in ICSharpCode.TextEditor.TexEditorControl and now I want to copy it to MS Word with these colors. If I do that by ctrl+c/ctrl+v all works fine. But how can I do it in c#?
Answers (3)
0
lszk

lszk

NA 5 0 16y
 I found somewhere that I have to save it in rtf file. In source code to this library I found a RtfWriter class. Like a paramether method to generate rtf needs TextArea object. But I have my TextEditorControl only. How to convert it?
0
lszk

lszk

NA 5 0 16y
There is a TextEditorControlBase.Text and with it I can copy the text to Word but without colors.
http://img155.imageshack.us/my.php?image=beztytuuccxke0.png

This is the reason why I posted this topic.
0
Scott Lysle

Scott Lysle

NA 28.5k 14.4m 16y

I am not familiar with that text editor control but with other controls such as a rich text box control, there are methods used to select all of the text, if select all of the text and copy it to the clipboard, you should be able to paste the contents with the formatting.  For a rich text box control, the code would look like this:

private void copyToolStripMenuItem_Click(object sender, EventArgs e)

{

rtbDoc.SelectAll();

Clipboard.SetText(rtbDoc.SelectedRtf, TextDataFormat.Rtf);

}