GetPreferredWidth() Question

Posted by: scottw-fp on 8 September 2017, 2:06 pm EST

  • Posted 8 September 2017, 2:06 pm EST

    I'm using version 3.0.2010.2005.  I'm trying to figure out how the various GetPreferredWidth() fxns should work.  I have a column header and the WordWrap is set to true.  When I call GetPreferredWidth(iColumn, false, true, true) I would expect the fxn to return a width that factors in the WordWrap column but it doesn't appear to be doing that.  Could you please explain how the WordWrap is supposed to be handled in the various GetPreferredWidth fxns?
  • Replied 8 September 2017, 2:06 pm EST

    Hello,

    When you have word wrap set to True the Width is getting re sized in accordance with the cell for Text not with the Headers cells.

    You need to turn WordWrap Off in order to set the ColumnWidth according to the width of the Text inside a cell.

    I hope it helps you.

     

    Thanks,

     

  • Replied 8 September 2017, 2:06 pm EST

    Hello,


    The problem you mention is a royal pain and one of the few things about spread that drive me nuts. For every project, I create a SetupSheetView method like this:


        Private Sub SetupFarPointSheetView(ByVal sheet As SheetView)
            Try
                With sheet
                    .SelectionUnit = Model.SelectionUnit.Cell
                    .DataAutoSizeColumns = False


                    ' Set row headers to no wrap.
                    Dim rowRendererNoWrapText As New CellType.RowHeaderRenderer
                    rowRendererNoWrapText.WordWrap = False
                    .RowHeader.DefaultStyle.Renderer = rowRendererNoWrapText


                    ' Set column headers to no wrap.
                    Dim columnRendererNoWrapText As New CellType.ColumnHeaderRenderer
                    columnRendererNoWrapText.WordWrap = False
                    .ColumnHeader.DefaultStyle.Renderer = columnRendererNoWrapText
                End With
            Catch ex As Exception
                Throw
            End Try
        End Sub 'SetupFarPointSheetView


    Once you have done the above, then you can use the sheetview GetPreferredColumnWidth method which has some overloads pertaining to column headers, spans, etc.


        With Me.FpSpread1.ActiveSheet
             For Each column As Column In .Columns
                column.Width = .GetPreferredColumnWidth(column.Index, False)
            Next
        End With


    Good Luck! It is a great product, but does have a few gotchas here and there.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels