Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Description

Excerpt

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

Signature
C#
C#
 public double GetTextHeight(System.String text, Font font, double desiredWidth)
{signature}{signature:
}
Signature
vb.net
vb.net
Public Function GetTextHeight(ByVal text As String, ByVal font As Font, ByVal desiredWidth As Double) As Double
{signature}
{parameters}
{param:text}The text string whose height will be calculated.{param}
{param:font}The font that will be used to format the text.{param}
{param:desiredWidth}The width, in character units, of the cell or area into which the text will be inserted.{param}
{returns}The minimum height, in character units, required to accommodate the given text string.{returns}
{remarks}
 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.
{remarks}

{example}{code:csharp|title=C#}
Parameters
Param
text
text

The text string whose height will be calculated.

Param
font
font

The font that will be used to format the text.

Param
desiredWidth
desiredWidth

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

Returns

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

Remarks

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.

Example
Code Block
csharp
csharp
titleC#


//--- 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);
{code} {code:
Code Block
vb.net
|title=
vb.net
titlevb.net
}


'--- 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)
{code} {example}