System.Runtime.InteropServices.COMException HResult=0x800A1767 Message=Es können keine individuellen Reihen in dieser Sammlung adressiert werden, weil die Tabelle vertikal verbundene Zellen enthält. Source=<Cannot evaluate the exception source> StackTrace: <Cannot evaluate the exception stack trace> |
The error occurs when you want to go through rows and columns in Word vba tables.
If cells have been linked horizontally or vertically in a table, enumeration after Table.Rows [n] or Table.Columns [n] is no longer possible
Here in C #
Because the table has linked cells, the program code causes an error in the Word add-in.
solution
Solution in vba or C # code.
One may only examine for Cells
cell = table.Cell(1, iCol); |
If a cell can not be captured, try-catch must break the error
Example Word traversing through C # in a Word addin
//*Loop all tables and look for header foreach (Word.Table table in _doc.Tables) { if (table.Rows.Count > 0) { int intColumns_Count = table.Columns.Count; for (int iCol = 1; iCol <= intColumns_Count; iCol++) { //----< @Loop: Columns in Table_Header >---- Cell cell = null; try { cell = table.Cell(1, iCol); if (cell.Range.Text.IndexOf(sHeader) == 0) { return table; } } catch (Exception) { //< endofcolumns > break; //</ endofcolumns > } //----</ @Loop: Columns in Table_Header >---- } } }
|