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

Free Support Forum - aspose.com

Automatic Row Height

The AutoFitRows method in Aspose sets the height of a row. Is there a way to set the row height to Excel's auto fit instead of an actual height?


Yes, the AutoFitRows method is used to auto-fit all the rows in a worksheet.

Is there a way to set the row height to Excel’s auto fit instead of an actual height?

You mean to say that AutoFitRow(s) does not work similar to MS Excel. Well, it might extends a row height a bit more to fit the contents in the cells and it might not be 100% accurate as MS Excel but it works in most cases. The interesting thing about auto-fitting rows/columns operation is that some users demand that autofit rows/columns should be more generous to allow some extra space to fit the data while others require a more reduced /condensed type of auto-fitting rows/columns with minimum space allowed to fit the data. I think we do in the middle of both but satisfy both :slight_smile:

Do you find any issue regarding auto-fitting rows in the sheet. If so, kindly post your template file(s), sample code etc. We will look into it soon.

Thank you.

Here is sample code to create a basic worksheet:

Dim wb As New Workbook()

Dim ws As Worksheet = wb.Worksheets(0)

With ws.Cells(0,0)

.PutValue("When you enable Internet Explorer Enhanced Security Configuration, it sets Internet Explorer security settings to limit how users brower Internet.")

.Style.IsTextWrapped = True

End With


wb.Save("c:\test.xls", FileFormatType.Excel97)

Open the generated file and take textwrap of the cell. You will notice that the height of the row is still the original height and not the hieght of the content. Excel's autofit would have shrunk the height of the row to the content of the cell which is one line of text. Can this be done with Aspose?


Well, this is how Auto-Fit Row operation works same as MS Excel. When you perform auto-fit operation either by the component or by MS Excel with text wrapped on, the height of the row is changed to fit the contents. Please check the attached output file using your code.

"Excel’s autofit would have shrunk the height of the row to the content
of the cell which is one line of text. Can this be done with Aspose?"
I suspect that perhaps you are talking about auto-fit column operation which related to width of the column.
If so, you may replace the line of code:



Also, kindly check the document:

If you still have any confusion, kindly let us know about it.

No, I am not referring to column width. They this series of steps and see if you understand what I am trying to accomplish:

1. Open generated Excel file.

2. On sheet1, select cell A1 and format the cell to remove text wrapping. When you do this, you will notice that the text does not wrap but the row height is still around 255.

3. Apply row autofit ( I am using Excel 2003, Format-->Row-->AutoFit). This will change row height to around 13.

4. Now re-apply text wrapping to the cell. When you do this, the row hieght will auto fit back to around 255.

Does this make since?


I think now we have understood the issue you are talking about. You mean to say the generated file by Aspose.Cells (in which we have wrapped a cell text with auto-fit row) does not auto-shrunk the row height to its original (default) height when we remove the wrap text attribute manually in MS Excel

We have added this issue to our issue tracking system with an issue id: CELLSNET-13839. We will inform you when it is sorted out.

Thank you.