VerticalAlignment and HorizontalAlignment

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

  • Posted 8 September 2017, 12:54 pm EST

    Hello,<br><br>I did a method to change alignment of cell content. <br>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.<br>I´m using the following code:<br> <pre class="coloredcode"> <span class="kwd">For Each</span> cr <span class="kwd">As</span> FarPoint.Win.Spread.Model.CellRange <span class="kwd">In</span> cellRange

    <span class="kwd">If</span> cr.Row = -1 <span class="kwd">Then
    If</span> cr.Column = -1 <span class="kwd">Then</span>
    Inicio = 0
    Fim = sheetView.Columns.Count - 1
    <span class="kwd">Else</span>
    Inicio = cr.Column
    Fim = cr.Column + cr.ColumnCount - 1
    <span class="kwd">End If

    For</span> Col <span class="kwd">As Integer</span> = Inicio <span class="kwd">To</span> Fim
    sheetView.Columns(Col).VerticalAlignment = Vertical
    sheetView.Columns(Col).HorizontalAlignment = Horizontal
    <span class="kwd">Next

    ElseIf</span> cr.Column = -1 <span class="kwd">Then</span>
    Inicio = cr.Row
    Fim = cr.Row + cr.RowCount - 1
    <span class="kwd">For</span> Row <span class="kwd">As Integer</span> = Inicio <span class="kwd">To</span> Fim
    sheetView.Rows(Row).VerticalAlignment = Vertical
    sheetView.Rows(Row).HorizontalAlignment = Horizontal
    <span class="kwd">Next

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

    End If
    Next</span>
    </pre> <br>However, it doesn´t work. Anything happens. <br>Do you get to see where the error is?<br><br>Best regards.<br>
  • Replied 8 September 2017, 12:54 pm EST

    <P>Hello,</P>
    <P>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.</P>
  • Replied 8 September 2017, 12:54 pm EST

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

    <P>Hello,</P>
    <P>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.</P>
  • Replied 8 September 2017, 12:54 pm EST

    Hi, Scott,<br><br>I´ve changed the alignment at the cell level. <br>Next, I want to change alignment of entire rows or columns.<br>When I try to do it, alignment of cells that was changed does not change. <br><br>You told me I need to reset their alignment at the cell level. <br>But this increase the processing time.<br>I´ve changed to this code to improve performance and not worsen it.<br><br>I´d like to know if it is possible to reset setting allignment of rows/columns at this level and not at cell level.<br><br>Thanks.<br>
    <br>
  • Replied 8 September 2017, 12:54 pm EST

    <P>Hello,</P>
    <P>There is not a way to have styles set at a column/row level overwrite styles set at a cell level.</P>
Need extra support?

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

Learn More

Forum Channels