Spread Windows Forms 17
In This Topic
    Center Across Selection
    In This Topic

    You can center align the contents of the selected cells across columns without merging the cells. This type of horizontal alignment can be set using the HorizontalAlignment.CenterAcrossSelection enumeration option from GrapeCity.Spreadsheet namespace. 

    In order to implement CenterAcrossSelection alignment option, FpSpread’s AllowCellOverflow must be set to true and FpSpread’s BorderCollapse must be set to ‘Enhanced’.

    centerAcrossSelection

    This example code sets the center across selection for the cells:

    C#
    Copy Code
    fpSpread1.AllowCellOverflow = true;
    fpSpread1.BorderCollapse = BorderCollapse.Enhanced;
    IWorksheet TestActiveSheet = fpSpread1.AsWorkbook().ActiveSheet;
    TestActiveSheet.Cells[1, 2].Text = "test feature setting";
    TestActiveSheet.Cells[1, 2, 1, 10].HorizontalAlignment = GrapeCity.Spreadsheet.HorizontalAlignment.CenterAcrossSelection; //set for big range
    TestActiveSheet.Cells[2, 2].Text = "test feature setting";
    TestActiveSheet.Cells[2, 2].HorizontalAlignment = GrapeCity.Spreadsheet.HorizontalAlignment.CenterAcrossSelection; //set for 1 cell
    TestActiveSheet.Cells[3, 2].Text = "test feature setting";
    TestActiveSheet.Cells[3, 2, 3, 3].HorizontalAlignment = GrapeCity.Spreadsheet.HorizontalAlignment.CenterAcrossSelection; //set for small range start from data cell
    TestActiveSheet.Cells[4, 2].Text = "test feature setting";
    TestActiveSheet.Cells[4, 1, 4, 2].HorizontalAlignment = GrapeCity.Spreadsheet.HorizontalAlignment.CenterAcrossSelection; //set for small range end by data cell
    
    VB
    Copy Code
    FpSpread1.AllowCellOverflow = True
    FpSpread1.BorderCollapse = BorderCollapse.Enhanced
    Dim TestActiveSheet As IWorksheet = FpSpread1.AsWorkbook().ActiveSheet
    TestActiveSheet.Cells(1, 2).Text = "test feature setting"
    TestActiveSheet.Cells(1, 2, 1, 10).HorizontalAlignment = GrapeCity.Spreadsheet.HorizontalAlignment.CenterAcrossSelection 'set for big range
    TestActiveSheet.Cells(2, 2).Text = "test feature setting"
    TestActiveSheet.Cells(2, 2).HorizontalAlignment = GrapeCity.Spreadsheet.HorizontalAlignment.CenterAcrossSelection 'set for 1 cell
    TestActiveSheet.Cells(3, 2).Text = "test feature setting"
    TestActiveSheet.Cells(3, 2, 3, 3).HorizontalAlignment = GrapeCity.Spreadsheet.HorizontalAlignment.CenterAcrossSelection 'set for small range start from data cell
    TestActiveSheet.Cells(4, 2).Text = "test feature setting"
    TestActiveSheet.Cells(4, 1, 4, 2).HorizontalAlignment = GrapeCity.Spreadsheet.HorizontalAlignment.CenterAcrossSelection 'set for small range end by data cell
    

    Using the Spread Designer

    1. In the work area, select the range of cells for which you want to set the center across selection.
    2. Select Spread from the drop-down list placed above the properties list.
    3. In the properties list (Appearance category), select the BorderCollapse property.
    4. Click the drop-down button to display the choices and choose Enhanced.
    5. Repeat the step and in the properties list (Behavior category), select the AllowCellOverflow property.
    6. Click the drop-down button to display the choices and choose True.
    7. From the Home menu, open Format Cells dialog box from the Alignment category.

      centerAcrossSelection_designer

    8. Click the drop-down button to display the choices and choose Center Across Selection
    9. Click OK to apply your changes.