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

Free Support Forum - aspose.com

Problem in Resizing a cell according to text size


I have a word template which has some fixed table structure. I populate these tables through my ASP.NET code. The problem, i am facing is that Table cells don't get resized according to the size of text which i populate into the cells of the tables. What code should i write to resize them. I have tried FitText and WrapText of CellFormat class but didn't achieve it. Please help me.


Thanks for your request. If FitText property is true, fits text in the cell, compressing each paragraph to the width of the cell. To allow auto fit you should set RowFormat.AllowAutoFit = true;. See the following example.

Document doc = new Document(@"055_88992_paragkale\in.doc");

NodeCollection nodes1 = doc.GetChildNodes(NodeType.Row, true);

foreach (Node node in nodes1)


Row row = (node as Row);

row.RowFormat.AllowAutoFit = true;

foreach (Cell cell in row.Cells)


Run run = new Run(doc);

run.Text = "test text in cell";

cell.CellFormat.Width = 1;





I hope that it will help you.

Hi, thankyou for a prompt reply,

but it didn't solve my problem. I am sending my word template as attachment. Actually i have fixed table structure in the template. Can i change the size of cells of my tables according to the text size rather than contracting the text size.


I have found solution to my problem

I have used

RowFormat.HeightRule = HeightRule.Auto;

And that solved my problem :-)

Thanx for all the support.

I am attempting to use this code to automatically size the cell according to the contained text. It isn’t working for me and when I view the document all the cells are extremely narrow (Width = 1). The one difference I’ve noticed is that I’m using a DocumentBuilder exclusively. Here’s the code I’m using…

Dim cell = builder.InsertCell()
cell.ParentRow.RowFormat.AllowAutoFit = True
cell.ParentRow.RowFormat.HeightRule = HeightRule.Auto
cell.CellFormat.VerticalAlignment = Tables.CellVerticalAlignment.Center
cell.CellFormat.Width = 1



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

Thanks for your request. Unfortunately, there is no way to set “Auto-fit to content” option using Aspose.Words. Maybe you can consider using template and mail merge approach to build the table. In this case, you will be able to configure table in MS Word.

Best regards.

The issues you have found earlier (filed as WORDSNET-2044) have been fixed in this .NET update and in this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.