Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read merged cell from word document

I am getting the below exception while reading the merged cell.

"Cannot access individual rows in this collection because the table has vertically merged cells."

My code is,

foreach (Row aRow in doc.Tables[i].Rows)
{
   foreach (Cell aCell in aRow.Cells)
   {
       MessageBox.Show(aCell.Range.Text);
   }
} 

// My table format is..

| R1C1 |R1C2|______|

| R2C1 |R2C2| R*C3 ..|

| R3C1 |R3C2|______|

like image 586
Aslam Avatar asked Jun 24 '14 13:06

Aslam


1 Answers

You could try the following:

Table table = Globals.ThisDocument.Tables[1];
Range range = table.Range;
for (int i = 1; i <= range.Cells.Count; i++)
{
    if(range.Cells[i].RowIndex == table.Rows.Count)
    {
        range.Cells[i].Range.Text = range.Cells[i].RowIndex + ":" + range.Cells[i].ColumnIndex;
        MessageBox.Show(range.Cells[i].Range.Text);
    }
}
like image 149
chridam Avatar answered Oct 21 '22 23:10

chridam