Remove cell borders when copying MS word table and pasting to RichTextBox control in C# (using office interop) RRS feed

  • Question

  • I am having pretty much working code that opens, copy and paste MS word file content to Winforms RichTextBox control.

    The content is from MS Word Table cell and the problem is, after pasting to Winform RichTextBox control, it is showing cell (black color) border as well.

    Any suggestion on how to remove border details and get only the richtext from Table cell. Constraint is, I am not allowed to modify word document.

    using word = Microsoft.Office.Interop.Word;
                var wordApp = new word.Application();
                var doc = wordApp.Documents.Open(Application.StartupPath + "\\TheDemo.doc");
                word.Range r;
                    foreach (word.Row aRow in doc.Tables[1].Rows)
                        foreach (word.Cell aCell in aRow.Cells)
                            richTextBox1.Rtf = Clipboard.GetData(System.Windows.Forms.DataFormats.Rtf).ToString();
                catch (Exception ex)
                    MessageBox.Show("Error: " + ex.Message + Environment.NewLine + ex.StackTrace);


    Blog: www.PavanGayakwad.blogspot.com Website: www.SrushtiSoft.com

    Saturday, March 23, 2013 4:37 AM


  • Hi PavanGayakwad,

    A workaround is to paste the cell content to a temp range without the borders and then copy the content from the temp range to the rich text box.

                    object start = doc.Tables[1].Range.End;
                    word.Range rng = doc.Range(ref start);// temp range.
                    foreach (word.Row aRow in doc.Tables[1].Rows)
                        foreach (word.Cell aCell in aRow.Cells)
                            word.ParagraphFormat temp = aCell.Range.ParagraphFormat;
                            rng.PasteAndFormat(word.WdRecoveryType.wdSingleCellText); // copy without borders.
                            // or clear the content before paste
                            // richTextBox1.Clear();
                    rng.Delete(); // delete the temp range.

    Good day.

    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Dummy yoyo Monday, April 1, 2013 3:29 AM
    Monday, March 25, 2013 1:14 PM