We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Fill table and add rows

I have a document with a table with 2 columns and 1 row.
I have a bookmark i the first cell. There is no text in the table.
I would like to add, lets say 4 rows af data to the table starting in the first (existing) row.
How do I add three rows to the table and fill the cells with data ?
(I keep getting nullpointerexception errors)
Best regards
Ole Kirkholt

Thanks for your request. I think that you can use DocumentBuilder class to achieve this. You should move to the cell, and then get current row and current table. Add some rows to table and fill cells. For example see the following code.

Document doc = new Document(@"337_101645_kirkholt\in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
// get current cell
Cell parentCell = builder.CurrentParagraph.ParentNode as Cell;
// get current row
Row parentRow = parentCell.ParentRow;
// get current table
Table parentTable = parentRow.ParentTable;
// add 10 rows to table
for (int i = 0; i < 10; i++)
// fill cels 
for (int i = 0; i < parentTable.Rows.Count; i++)
    for (int j = 0; j < parentTable.Rows[i].Cells.Count; j++)
        builder.MoveToCell(0, i, j, 0);
        builder.Write(String.Format("Row index = {0}; Cell index = {1}", i.ToString(), j.ToString()));
// save document

I hope that this will help you.
Best regards.