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

Free Support Forum - aspose.com

FitTableToPageWidth function

Hi - in your .Net programming API documentation, I noticed you have coded a function to "fit table columns to page width". Do you have a corresponding function to "fit table columns to page height"?

I appreciate all of your help in answering my questions so quickly.


Hi Todd,

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

Thanks for your inquiry. I am not sure it is clear for me how this should work. Could you please attach your input document and the expected output? I will check your documents and try to help you.

Do you have “vertical” table in your document?

Best regards,

We are using Aspose to convert an Excel document to a Word document. In Excel, you can specify to fit the worksheet on one page (width and height). You provide a means to shrink the width of a document. I also need to shrink the height of a document to fit on one page. Do you have any ideas on how I might accomplish that utilizing your .net “word” API?

Hi Todd,

Thanks for this additional information.

Yes, this sounds possible in theory but is harder in practice. Row heights can be defined at an exact height, or as at least a certain height or calcuated automatically to fit contents. Due to this some rows which are set as Auto or At Least may not define a height at all which makes resizing them in tables very hard.

Could you attach a sample document here for insepction. In any case the table can still be fitted to the page height but with equal sized rows. This unfortunately means that row proportions will not be retained.



I have tried multiple approaches to either shrink the font or shrink the row height - but, none of my changes are reflected when converting an Excel sheet to Word. Here is my latest code:

double containerHeight = 0;
double tableHeight = 0;
double ratio = 0;

containerHeight = builder.PageSetup.PageHeight - (builder.PageSetup.TopMargin + builder.PageSetup.BottomMargin);

foreach (Aspose.Words.Tables.Row row in table.Rows)
tableHeight += row.RowFormat.Height;

if (tableHeight > containerHeight)
ratio = containerHeight / tableHeight;
builder.ParagraphFormat.KeepWithNext = true;
builder.Font.Size = 8;
RowFormat rowFormat = builder.RowFormat;
rowFormat.Height = rowFormat.Height * ratio;

Any suggestions on how best to either adjust the font of a table to a small size or set the rowheight?


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

Thanks for your inquiry. Have you tried using Excel2Word demo to convert Excel files to Word document? Maybe it will produce the desired output. You can find this demo here:


Best regards,