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

Free Support Forum - aspose.com

How to add/create tables in word document at run time?

Hi,

I have an empty word document. I am trying to dynamically add/create a table with 3 columns and 2 rows in this document (numbers may vary). How can we do this? Please help.

Thank you.

Hi

Thanks for your inquiry. The easiest way to create table is using Documentbuilder. Please see the following link for more information.

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/inserting-document-elements.html

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Also see the following code example:

//Create new Document and DocumentBuilder

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

//Set borders

builder.CellFormat.Borders.LineStyle = LineStyle.Single;

builder.CellFormat.Borders.Color = Color.Red;

//Generate simple table

for (int i = 0; i < 2; i++)

{

for (int j = 0; j < 3; j++)

{

//Insert cell

builder.InsertCell();

builder.Write("test");

}

builder.EndRow();

}

builder.EndTable();

//Save document

doc.Save(@"Test\out.doc");

Hope this helps.

Best regards,