Hi,
I am having some difficulty navigating through a table which is defined in my word template. The table contains 2 rows; the first is a header row, and the second row contains 5 cells, with a bookmark in the first cell.
I want to navigate to the bookmark in the first cell of the second row, and insert some value there. I also need to go through the other 4 cells on that row, and insert appropriate data there.
Lastly, I will need to be able to add more rows beneath the second row, with the same amount of cells, and input textual values there.
When I try to use the DocumentBuilder.MoveToCell() method, I get an error message stating that the first argument, namely the table index, is out of range:
“ArgumentOutOfRangeException was unhandled. Specified argument was our of the range of valid values.”
Please help me to understand what I am doing wrong.
Here is an excerpt of my code:
Aspose.Words.Document whatsUpDoc = LoadDocument(documentPath + documentName);
foreach(Aspose.Words.Bookmark bookmarkItem in whatsUpDoc.Range.Bookmarks)
{
if (bookmarkItem.Name.Equals("BookmarkImLookingFor"))
{
DocumentBuilder docBuilder = new DocumentBuilder(whatsUpDoc);
docBuilder.MoveToBookmark(bookmarkItem.Name);
Cell cellWithBookmark = docBuilder.CurrentParagraph.ParentNode as Cell;
Row rowWithBookmark = cellWithBookmark.ParentRow;
Table tableWithBookmark = rowWithBookmark.ParentTable;
// I need these indexes for the MoveToCell method
int tableIndex = tableWithBookmark.ParentNode.IndexOf(tableWithBookmark);
int rowIndex = tableWithBookmark.IndexOf(rowWithBookmark);
int cellIndex = rowWithBookmark.IndexOf(cellWithBookmark);
for (int i = cellIndex; i <rowWithBookmark.Cells.Count; i++)
{
docBuilder.MoveToCell(tableIndex, rowIndex, cellIndex, 0);
docBuilder.Write("cell " + i.ToString());
}
}
}