Free Support Forum -

Insert rows to existing table

If I am just missing something then please advise otherwise this is a feature request. I basically load a few templates into a main document. This is nice because the end user can format the template as they like and set bookmarks where they desire.

One of these templates is a table with headers and a blank row. I am able to insert this template into my main document and then navigate to the first cell by .MoveToCell(…). Once this row is filled with data I want to insert a new row and then add cells and insert data. This is where I have run into a problem. It seems that .EndRow keeps throwing an error saying “can not end a row while not building a table.”. I really do not want to use a table builder because I dont want to have a lot of formatting in the code (the purpose of the templates is that the end user can handle the formatting). I am however able to call .InsertCell but this does not help me if I can not insert a new row to an existing table.

I am doing this all in COM.

David A.

Hi David,

Thank you for your interest in Aspose.Word.

Sorry, we don’t have special methods to grow an existing table at the moment. So this is actually a feature request; however, we know that this feature would be very useful and we already have it in our task list. We’ll try to implement it asap.

Dmitry was talking about using DocumentBuilder to grow existing tables in a document and it is not supported at the moment.

However, there is a way to fill existing table with data - use mail merge with regions. You can create a table in your document normally consisting of header row(s) and one data row that contains mail merge fields - then you can call MailMerge.ExecuteWithRegions to populate the table with records from a data source such as DataTable.

See the demos included with Aspose.Word for examples on how to do this.

If I understand mail merges correctly a user creating the word template would always need a connection to the database. Unfortunately I am in a situation where this is not plausible.

Looking foward to the update I will probably stick with creating the table from scratch now with DocumentBuilder.

No database connection needed. In MS Word just go to Insert/Field, select Merge Field and enter the field name you want.

The .Execute for a mailmerge requires the use of an ado or data object so I can not use it here. I will wait for the next release. Smile

ADO.NET DataTable is actually very easy to use without a database connection. You can create one in memory from scratch (I mean add columns, rows of data) or load it from an XML file. Of course you can load it from a database connection (data adapter to be more exact), but you don’t have to.

We use plenty of DataTable objects in our unit tests without using any database.

Here is an example included in the documentation for MailMerge.Execute:

//This example creates a table, but you would normally load table from a database.

DataTable table = new DataTable(“Test”);



table.Rows.Add(new object[] {“James Bond”, “MI5 Headquarters”});

table.Rows.Add(new object[] {“Roman Korchagin”, “Auckland, Birkdale”});

//Field values from the table are inserted into the mail merge fields found in the document.



Unfortunately I can not use .net for this and am calling ASPOSE through COM. There are many spots where data is stored in datastructures that I need to loop through and insert data into the document.