Steve 5656565656

Hello all,

Is there any way to take a selection from MS Word using VSTO, and convert that selection to rtf Right now here is the code which uses the clipboard:

private string ConvertToRTF(Word.XMLNode node)

{

string strData = "";

try

{

// Copy to clipboard (This will erase the clipboard contents that the user entered into here before!!!

node.Range.Copy();

strData = Clipboard.GetText(TextDataFormat.Rtf);

Clipboard.Clear();

}

catch (Exception ex)

{

Trace.WriteLineIf(logic.ASI3Reporting.TraceError, "Error converting to rtf: " + ex.ToString(), "Errors");

string ss = ex.ToString();

}

return strData;

}

The problem with the code is that the clipboard contents are now replaced with my selection thus replacing the value at the top of the clipboard stack so the end user won't have their original copied data. I need to copy this because this is the only way that I can get the selection converted to rtf. Another method would require saving the entire document to disk as rtf but this would only work for the entire document, whereas, I need to convert only a selection.

Any help would be greatly appreciated.



Re: Visual Studio Tools for Office Convert a selection and convert it to rtf

Cindy Meister

Hi Steve

clipboard or save to disk is the only way to get the text converted for you. If we're talking Word 2003 or 2007 you'd have the option of transforming WordProcessingML to RTF, but unless you can find a third-party tool you'd have to write all the transformation code yourself.






Re: Visual Studio Tools for Office Convert a selection and convert it to rtf

Steve 5656565656

Does anyone know of any 3rd party tools out there that would help me with this I am developng for MS Word 2003.



Re: Visual Studio Tools for Office Convert a selection and convert it to rtf

Cindy Meister

You might check whether AltSoft has one. They do for WordML to PDF, for example.