Reputation: 93
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|______|
Upvotes: 7
Views: 5874
Reputation: 22866
Table.Range.Cells can be enumerated:
foreach (Cell cell in doc.Tables[i].Range.Cells)
{
Debug.Print(cell.Range.Text);
}
Upvotes: 0
Reputation: 103335
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);
}
}
Upvotes: 8