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

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

The text string whose width will be calculated.

The font that will be used to format the text.

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

The minimum width, in character units, required to accomodate the given text string.

The maximum width of any one column is 409 character units, so if the width return is greater than 409, you must merge cells across multiple columns and set the width of each column to accomodate the total minimum width of the text.


          //--- What is the height of row 1?
          RowProperties rowProps = worksheet.GetRowProperties(0);

          //--- How wide will the data be?
          double requiredWidth =
               wb.GetTextWidth(longTextString,
               rowProps.Style.Font,
               rowProps.Height);

          //--- Will we need multiple columns to display all of the data?
          //--- Can not exceed 255 character units in width per column.
          int numCols = (int) Math.round((requiredWidth / 255) + 0.5);

          //--- Evenly distribute the required width between all of the columns.
          worksheet.Cells[0, 3].Value = longTextString;
          a = worksheet.createArea(0, 3, 1, numCols);
          a.MergeCells();
          a.AllColumnWidthsInChars = (requiredWidth / numCols);
        

          '--- What is the height of row 1?
          Dim rowProps As RowProperties = worksheet.GetRowProperties(0)

          '--- How wide will the data be?
          Dim requiredWidth As Double = _
               wb.GetTextWidth(longTextString, _
               rowProps.Style.Font, _
               rowProps.Height)

          '--- Will we need multiple columns to display all of the data?
          '--- Can not exceed 409 character units in width per column.
          Dim numCols As Integer = Math.Round((requiredWidth / 409) + 0.5)

          '--- Evenly distribute the required width between all of the columns.
          worksheet.Cells(0, 3).Value = longTextString
          Dim a As Area = worksheet.CreateArea(2, 2, numRows, 1)
          a.MergeCells()
          a.AllColumnWidthsInChars = (requiredHeight / numRows)