Cell height different when using "AutoFitRows" function of Aspose.Cells and MS Excel auto-fit rows operation in .NET

When I use worksheet.AutoFitRows I get 60 pixels row height, but when I use Excel “AutoFit Row Height” I get 100 pixel row height.

autofit from excel.png (12.8 KB)

AutoFitRowsTest.zip (3.2 KB)

@AdamMada,

This is due to the following line of code. This line is unnecessary, so kindly remove it.

options.AutoFitMergedCellsType = AutoFitMergedCellsType.EachLine;

This line is only applicable if you have merged cell(s) in the sheet.

Let us know if you still have any issue.

Thank You for quick answer.
Now row in the file have correct height but when I get height from the code I receive 60 pixels, not 100.
Do You maybe know how to calculate correct height, from the code, which Is the same like in Excel file?
I’ve tried worksheet.Cells.GetRowHeightPixel(0) or even
TextRenderer.MeasureText(text, font, new Size(columnWidth, 0), TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak) but wihout success. I couldn’t get correct 100 pixels height programatically based on text “aaaaaaaa aaaaaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaaaaa aaaaaaaa”.

height.png (8.0 KB)

@AdamMada,
We have observed this issue and logged it in our database for further investigation. We will notify you here once any update is ready for sharing.

This issue is logged as:
CELLSNET-48013 - Cells.GetRowHeightPixel() returns different value as compared to row height returned by MS Excel

I’m looking forward to your reply, thank You.

@AdamMada,
After auto fitting row height , the property Row.IsHeightMatched must be set as true. It works as MS Excel.
And MS Excel will auto fit row height again when opening the file if Row.IsHeightMatched is true. 100 is the strange result of MS Excel.

We will add AutoFitterOptions.IsHeightMatched propery to set the property Row.IsHeightMatched in the next fix.

@AdamMada,
We have noticed that MS Excel is very strange that 60 pixels can display the contents of a cell, but it has to be 100 pixels. At present, the API automatically adapt the row height to 60 and cannot get 100.
Our original solution was not to let MS Excel auto fit row height when opening the file. If you can accept it, we will continue to add this attribute.

Let us know your feedback.

For me this solution is not much helpful. I want to get proper height immediately, without opening Excel file.

@AdamMada,

Thanks for your feedback.

We will evaluate it further and get back to you soon.

@AdamMada,

We evaluated your issue further and I am afraid, we cannot return 100 pixels as MS Excel now because 60 pixels is enough to show all text. We cannot understand why MS Excel needs one more line.

1 Like