tags:

views:

361

answers:

1

Context : I embedded Word into a Winforms using the DSOFramer sample published by Microsoft. Now, I can write text with all formatting options of a Word document.

Question : I can extract the basic text from the doc, using doc.Content.Text (doc is a reference to my Word document), but i can't figure out how I can get the text with formatting, either as RTF or as HTML. I hopped Word docs had something similar to the Rtf attribute in the RichTextBox, but it doesn't seem so. So how am I supposed to get the formatted text ?

+1  A: 

You can use the clipboard:

Microsoft.Office.Interop.Word.Document doc = 
    axFramerControl1.ActiveDocument as Microsoft.Office.Interop.Word.Document;
doc.Content.Select();
doc.Content.Copy();
this.richTextBox1.Paste();
jmservera
Thanks for the suggestion. I already thought of that, but more as a last resort for 2 reasons. 1- that would mean having a hidden RichTextBox to paste the content into and do the formatting for me. 2- As a user, i hate applications who feel they own the clipboard. The clipboard is supposed to be for the user personal use. But i guess i could save its content and restablish it as soon as I have made my conversion. Still it's quite a ugly workaround. I hope Doc format offers us more than that.
Ksempac
The only alternative option I know is to do a doc.SaveAs to RTF and then read it from disk (http://www.codeproject.com/KB/cs/convertdocintootherformat.aspx).
jmservera