Hernán
Hernán

Reputation: 4587

OL 2007 Addin: Get HTML formatted selection from Outlook inspector window

I'm working with an addin where I need to transform selected text in an Outlook editor, specifically the Compose inspector.

The text transformation should not ignore the text formatting present, so I was thinking of getting the HTML formatted text from the selection.

Outlook 2007/2010 Compose inspector item is in Word format, so i've used the "copy to clipboard" trick to get the current selection, transform it to Range, copy to clipboard and get the HTML formatted data back as follows:

private static void XFormMail(Inspector insp)
{
    Word.Document doc = (Word.Document)insp.WordEditor;
    Word.Selection sel = doc.Windows[1].Selection;
    Word.Range range = sel.Range;

    Debug.WriteLine(String.Format("Selection chars: {0}", sel.Characters.Count));
    Debug.WriteLine(String.Format("Selected text: {0}", sel.Text));
    Debug.WriteLine(String.Format("Selected XML: {0}", sel.XML));

    range.Copy();
    string h = (string)Clipboard.GetData(DataFormats.Html).ToString();
}

There is any way to get HTML directly from selection object without using Clipboard or exporting range to temp file as HTML?

Thanks in advance.

Upvotes: 0

Views: 483

Answers (1)

Homero
Homero

Reputation: 246

Im not sure, but try the methods Range.Paste, Range.PasteSpecial and Range.PasteFormat. i use this methods in Excel.Range in smiliar situations. office applications has an own clipboard but no way to access programaticly(sad)

Upvotes: 1

Related Questions