none
c# ms-word table: how to merge portions of a long column? RRS feed

  • Question

  • The c# code created a very long table in MS-word file. Then two cells in one column are being merge (1,5) (2,5). It works (see code below).

    Then, if I try to merge two more cells in same column e.g. (5,5), (6,5) - I get the following error: "Cannot access individual rows in this collection because the table has vertically merged cells"

    The real target is to merge several group of cells in the same column, and in other columns, after the table is created.

    How can I merge several groups of cells in same column? 

    The code used to create the table and merge:

                for (int i=1;i<=100;i++)
                {
                    genTable.Rows[i].Cells[1].Range.Text = (100 + i).ToString();
                    genTable.Rows[i].Cells[2].Range.Text = (200 + i).ToString();
                    genTable.Rows[i].Cells[3].Range.Text = (300 + i).ToString();
                    genTable.Rows[i].Cells[4].Range.Text = (400 + i).ToString();
                    genTable.Rows[i].Cells[5].Range.Text = (500 + i).ToString();
    
                }
    
                genTable.Rows[1].Cells[5].Merge(genTable.Rows[2].Cells[5]);
    
                genTable.Rows[5].Cells[5].Merge(genTable.Rows[6].Cells[5]);

    Thursday, March 28, 2019 9:42 AM