Message-ID: <85869421.8911.1711667862030.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8910_473915792.1711667862030" ------=_Part_8910_473915792.1711667862030 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Returns the minimum height required to fit the given text string using t= he given font.
=20public double GetTextHeight(System.String text, Font font, double desiredW= idth)=20
Public Function GetTextHeight(ByVal text As String, ByVal font As Font, ByV= al desiredWidth As Double) As Double=20
//--- What is the width of column C? ColumnProperties colProps =3D worksheet.GetColumnProperties(2); //--- How tall will the data be? double requiredHeight =3D 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 =3D (int) Math.Round((requiredHeight / 409) + 0.5); //--- Evenly distribute the required height across all of the rows. worksheet.Cells[2, 2].Value =3D longTextString; Area a =3D worksheet.CreateArea(2, 2, numRows, 1); a.MergeCells(); a.AllRowsHeight =3D (requiredHeight / numRows);=20
'--- What is the width of column C? Dim colProps As ColumnProperties =3D worksheet.GetColumnProperties(2) '--- How tall will the data be? Dim requiredHeight As Double =3D 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 =3D Math.Round((requiredHeight / 409) + 0.5) '--- Evenly distribute the required height across all of the rows. worksheet.Cells(2, 2).Value =3D longTextString Dim a As Area =3D worksheet.CreateArea(2, 2, numRows, 1) a.MergeCells() a.AllRowsHeight =3D (requiredHeight / numRows)=20