Returns the minimum height required to fit the given text string using the given font.

 public double GetTextHeight(System.String text, Font font, double desiredWidth)
Public Function GetTextHeight(ByVal text As String, ByVal font As Font, ByVal desiredWidth As Double) As Double

The text string whose height will be calculated.

The font that will be used to format the text.

The width, in character units, of the cell or area into which the text will be inserted.

The minimum height, in character units, required to accommodate the given text string.

The maximum height of any one row is 409 units, so if the height return is greater than 409, you must merge cells across multiple rows and set the height of each row to accommodate the total minimum height of the text.


//--- What is the width of column C?
ColumnProperties colProps = worksheet.GetColumnProperties(2);

//--- How tall will the data be?
double requiredHeight = wb.GetTextHeight(longTextString,
                                         colProps.Style.Font,
                                         colProps.WidthInChars);

//--- Will we need multiple rows to display all of the data?
//--- Can not exceed 409 character units in height per row.
int numRows = (int) Math.Round((requiredHeight / 409) + 0.5);

//--- Evenly distribute the required height across all of the rows.
worksheet.Cells[2, 2].Value = longTextString;
Area a = worksheet.CreateArea(2, 2, numRows, 1);
a.MergeCells();
a.AllRowsHeight = (requiredHeight / numRows);

'--- What is the width of column C?
Dim colProps As ColumnProperties = worksheet.GetColumnProperties(2)

'--- How tall will the data be?
Dim requiredHeight As Double = wb.GetTextHeight(longTextString, _
                                                colProps.Style.Font, _
                                                colProps.WidthInChars)

'--- Will we need multiple rows to display all of the data?
'--- Can not exceed 409 character units in height per row.
Dim numRows As Integer = Math.Round((requiredHeight / 409) + 0.5)

'--- Evenly distribute the required height across all of the rows.
worksheet.Cells(2, 2).Value = longTextString
Dim a As Area = worksheet.CreateArea(2, 2, numRows, 1)
a.MergeCells()
a.AllRowsHeight = (requiredHeight / numRows)