Exception when execute Aspose.Words.DocumentBuilder.MoveToCell. (Table Index)

Hi,

I am trying to change the background color of some cells in a table. The table is the second table in that doc, but I fail to point to it by using index 1. I am confused about the table index. How can I decide the index of a table.

There is the code:

Document doc = new Document(iniDocStr); // iniDocStr is the place where the template locate.
DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToCell(1, 1, 1, 0);

builder.CellFormat.Shading.BackgroundPatternColor = rowColor;

There is the exception:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: tableIndex
at Aspose.Words.DocumentBuilder.ᐾ(Int32 ᐿ, Int32 ა)
at Aspose.Words.DocumentBuilder.MoveToCell(Int32 tableIndex, Int32 rowIndex, Int32 columnIndex, Int32 characterIndex)
at ReportWebService.shortFormGenerator.generateDocument(VLNValuation valuationSchema) in c:\inetpub\wwwroot\reportwebservice\shortformgenerator.cs:line 458

I attached the template MS Word file.

Thanks a lot.

Hi,

Obviously this happens because, as the API reference for the MoveToCell method states, the navigation is performed inside the current story of the current section. Your document consists of multiple sections and the second table is actually the first table of the second section. So in the beginning you should move to the second section:

builder.MoveToSection(1)

and then move to a cell in the first table of the section:

builder.MoveToCell(0, 1, 1, 0);