[英]How to read merged cell from word document
我在讀取合並單元格時遇到以下異常。
“無法訪問此集合中的各個行,因為該表具有垂直合並的單元格。”
我的代碼是,
foreach (Row aRow in doc.Tables[i].Rows)
{
foreach (Cell aCell in aRow.Cells)
{
MessageBox.Show(aCell.Range.Text);
}
}
//我的表格式是..
| R1C1 | R1C2 | ______ |
| R2C1 | R2C2 | R * C3 .. |
| R3C1 | R3C2 | ______ |
您可以嘗試以下方法:
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);
}
}
可以枚舉Table.Range.Cells:
foreach (Cell cell in doc.Tables[i].Range.Cells)
{
Debug.Print(cell.Range.Text);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.