WrapText and RowHeight

After wrapping text and expending the row height to for example 5 rows the function RowHeight still delivers 255.
How can the height properly be calculated after a text wrap?

Hi,
I am not sure I fully understand the question. How are you expanding the row height? Are you autofitting the rows? (see FlexCel API Developer Guide | FlexCel Studio for VCL and FireMonkey documentation )

The row height should change when you autofit, but not if you don't, because of the reasons in the link above. But again, I am not sure I am understanding the question. Can you post a little example code? Thanks!

My code is as foillows:

var fmt := xls.GetCellVisibleFormatDef(_row, 1);
fmt.WrapText := True;
xls.SetCellFormat(_row, 1, xls.AddFormat(fmt));
rowHeight := xls.GetRowHeight(_row)

As a result the text in my Excel file is nicely wrapped, but the calculated row height is 255 instead of 255 * 5. What do I miss?

image

The column width is set to a fixed number.

Hi,
Try with:

By default, FlexCel won't autofit rows unless you manually do it. It will let them in "autofit" mode though, so when you open the file in Excel you will see it correctly. But if you want to read the row height as in this case, of you want to export the file to pdf or similar, you need to call Autofit to force FlexCel to do it. The reason we don't do it automatically is just that Autofit won't return always the same thing: how much text fits in a row depends in the monitor resolution, and sometimes it might need 2 rows, but sometimes it might fit in 1.

Notes:

  1. This will likely work, but if it doesn't, you might need to set TExcelFile.CellMarginFactor := 1.1 as mentioned in Fine-tuning row autofitting. | FlexCel Studio for VCL and FireMonkey documentation

  2. For this case, AutofitRow is the obvious choice, but sometimes, you migth want to set the full workbook first, and then autofit all rows at the end. For that case, AutofitRowsOnWorkbook will work better.