Jagrut

Hi everybody,

I have to fill up a Word Table with text entered in a MS RichTextBox control. Within the control user can apply various formattings like text alignments, bold, etc. to the text. The RTF text received from the RichTextBox control is then filled in a table cell. There are many such RichTextBox controls. Each control's content will occupy one table cell.

The RichTextBox content is transferred to a table cell via Clipboard as follows:

Clipboard.SetText(cellContent, TextDataFormat.Rtf);

myTable.Cell(row, column).Range.Paste();

Clipboard.Clear();

Here cellContent contains a valid RTF as given by RichTextBox controls.

Now the problem is that one blank line gets inserted within each cell after the cell content. I am not sure what might be wrong but after some observations I felt that it might be due to "/par" RTF command being suffixed after the actual text. I tried removing "/par" RTF code but then text alignment stopped working.

I am using VSTO 2005 and MS Word 2003

Thanks is advance.

Jagrut




Re: Visual Studio Tools for Office Pasting RTF into a table cell

Cindy Meister

I think your analysis is probably correct. The end-of-cell marker in a Word table contains a "paragraph mark", which appears to be a simple ANSI 13. In reality, however, the paragraph mark also contains (actually points to) all paragraph-level formatting. In removing the paragraph mark in the RTF, you're therefore letting the table cell's default formatting override what's being pasted into the cell.

I'm afraid the only way you're going to get this to work is to do some automation work on the Word table after pasting the RTF. Try deleting the paragraph mark after pasting; it will be the third character from the right in the Cell(row, column).Range.






Re: Visual Studio Tools for Office Pasting RTF into a table cell

Jagrut

Hi Cindy,

Thanks very much for the reply. It worked for me.

Jagrut