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

Free Support Forum - aspose.com

How to create nested table

Hi Aspose Team,

We have requirement to create nested table in certain row for specific purpose as depicted in attached attachement. Requirement is like there is a parent table. In certain row of parent table there may condition that that row may have data as form of table. We are creating the table manually using aspose library. also we have to ensure that the row which contains nested table should not split on multiple pages.

Please help us to create such table programatically using Aspose library as depicted in attached document. Please let us know if you need more information on that.

thanks

arvind

Attaching sample document.

Hi Arvind,


Thanks for your inquiry. Sure, you can create a similar nested table by using the following code snippet:

DocumentBuilder builder = new DocumentBuilder();

builder.Font.Name = "Calibri";

builder.Font.Size = 11;

builder.RowFormat.HeightRule = HeightRule.AtLeast;

builder.RowFormat.Height = 0.29 * 72;

Table parentTable = builder.StartTable();

builder.InsertCell();

builder.Write("1st Row");

builder.InsertCell();

builder.InsertCell();

builder.EndRow();

builder.InsertCell();

builder.Write("2nd Row");

builder.InsertCell();

builder.InsertCell();

builder.EndRow();

builder.InsertCell();

builder.Write("3rd Row");

builder.InsertCell();

builder.InsertCell();

builder.EndRow();

builder.InsertCell();

Table nestedTable = builder.StartTable();

builder.InsertCell();

builder.Write("4th sub row 1");

builder.EndRow();

builder.InsertCell();

builder.Write("4th sub row 2");

builder.EndRow();

builder.InsertCell();

builder.Write("4th sub row 3");

builder.EndRow();

builder.InsertCell();

builder.Write("4th sub row 4");

builder.EndRow();

builder.EndTable();

nestedTable.PreferredWidth = PreferredWidth.FromPoints(1.13 * 72);

builder.InsertCell();

builder.InsertCell();

builder.EndRow();

builder.InsertCell();

builder.Write("5th Row");

builder.InsertCell();

builder.InsertCell();

builder.EndRow();

builder.InsertCell();

builder.Write("6th Row");

builder.InsertCell();

builder.InsertCell();

builder.EndRow();

builder.EndTable();

parentTable.PreferredWidth = PreferredWidth.FromPoints(3.88 * 72);

builder.Document.Save(@"C:\temp\out.docx");


Please also watch this video to learn how to create Table from scratch, insert content inside this table and apply different formatting using DocumentBuilder class.

I hope, this helps.

Best regards,