VerticalAlignment and HorizontalAlignment

Posted by: fhcnunes-fp on 8 September 2017, 12:54 pm EST

  • Posted 8 September 2017, 12:54 pm EST

    Hello,

    I did a method to change alignment of cell content.
    To improve performance, I change VerticalAlignment and HorizontalAlignment properties of columns/rows and not these properties of cells when I want to change alignment of columns/rows entirely.
    I´m using the following code:
     
                For Each cr As FarPoint.Win.Spread.Model.CellRange In cellRange

    If cr.Row = -1 Then
    If
    cr.Column = -1 Then
    Inicio = 0
    Fim = sheetView.Columns.Count - 1
    Else
    Inicio = cr.Column
    Fim = cr.Column + cr.ColumnCount - 1
    End If

    For
    Col As Integer = Inicio To Fim
    sheetView.Columns(Col).VerticalAlignment = Vertical
    sheetView.Columns(Col).HorizontalAlignment = Horizontal
    Next

    ElseIf
    cr.Column = -1 Then
    Inicio = cr.Row
    Fim = cr.Row + cr.RowCount - 1
    For Row As Integer = Inicio To Fim
    sheetView.Rows(Row).VerticalAlignment = Vertical
    sheetView.Rows(Row).HorizontalAlignment = Horizontal
    Next

    Else
    For
    Row As Integer = cr.Row To cr.Row + cr.RowCount - 1
    For Col As Integer = cr.Column To cr.Column + cr.ColumnCount - 1
    With sheetView.Cells(Row, Col)
    .VerticalAlignment = Vertical
    .HorizontalAlignment = Horizontal
    End With
    Next
    Next

    End If
    Next

     
    However, it doesn´t work. Anything happens.
    Do you get to see where the error is?

    Best regards.
  • Replied 8 September 2017, 12:54 pm EST

    Hello,


    If you have previously set the HorizontalAlignment or VerticalAlignment on a cell, then you would not be able to changer this allignment setting the property on a Row/Column. You would need to reset the alignment set at the cell level, before being able to set it at the Row/Column level.

  • Replied 8 September 2017, 12:54 pm EST

    But if I reset alignment at the cell level, I will lose the performance.
    Is there a way more efficient?
  • Replied 8 September 2017, 12:54 pm EST

    Hello,


    If you are setting allignment (or any other style) at the cell level, then you would have to reset this setting before setting the style at a row/column level. If you do not, then the row/column setting will be overwritten by the cell level setting of the same property. This is documented under the Customizing the Appearance of a Cell under the User's-Task Documentation.

  • Replied 8 September 2017, 12:54 pm EST

    Hi, Scott,

    I´ve changed the alignment at the cell level.
    Next, I want to change alignment of entire rows or columns.
    When I try to do it, alignment of cells that was changed does not change.

    You told me I need to reset their alignment at the cell level.
    But this increase the processing time.
    I´ve changed to this code to improve performance and not worsen it.

    I´d like to know if it is possible to reset setting allignment of rows/columns at this level and not at cell level.

    Thanks.


  • Replied 8 September 2017, 12:54 pm EST

    Hello,


    There is not a way to have styles set at a column/row level overwrite styles set at a cell level.

Need extra support?

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

Learn More

Forum Channels