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

Free Support Forum - aspose.com

When I am creating a table with rows that have different cell numbers- the rows can't have same width


When I am creating a tables that contains dynamic cells in rows, I can’t keep the rows staying in same width. I tried the following methods and all failed.

Method #1:

Table table=new Table(doc);
Row row1 = new Row(doc);
row1.Cells.Add(new Cell(doc));

Row row2 = new Row(doc);
row2.Cells.Add(new Cell(doc));
row2.Cells.Add(new Cell(doc)); 

Method #2:
Using DocumentBuilder to build the above table.

Method #3:
Creating a 2X2 table, and then merge the 2 cells in the 1st Row.

Please see attached screen shot. Please let me know how I can create the expected table with rows staying in same width.

Thank you!

Hi Jiang,

Thanks for your inquiry. You can achieve your requirements by using CellFormat.HorizontalMerge property. I suggest you please read following documentation link for your kind reference.

Following code example creates a table with two rows with cells in the first row horizontally merged.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.Write("Text in merged cells.");
// This cell is merged to the previous and should be empty.
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.CellFormat.HorizontalMerge = CellMerge.None;
builder.Write("Text in one cell.");
builder.Write("Text in another cell.");
doc.Save(MyDir + "AsposeOut.docx");

Moreover, please read following forum link for your kind reference.

Hope this helps you. Please let us know if you have any more queries.

Hello Tahir Manzoor,

So sorry for the delay as I am Chinese in a different time zone.

Thank you so much for your response!

But I tried this solution before I sent this query to you. But I failed. Now I will attached what I got in my document.

I am using Aspose.Words version My IDE is VS 2010. My project is under .net 3.5.

Thank you!

Best Regards,

Hi Jiang,

Thanks for your inquiry. We encourage you to please use the latest version of Aspose.Words as it contains newly introduced features, enhancements and fixes for issues reported earlier. So, I would suggest you please upgrade to the latest version (v13.2.0) from here:

The new version of Aspose.Words will solve your problem. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.