Formatting in WPF SpreadsheetControl (Classic)

4 May 20212 minutes to read

Conditional Formatting

Conditional formatting is a feature by which cell styles will be dynamically formatted based on its value and specified condition. It enables you to apply formatting to the cell through a dialog window.

Use Case Scenarios

This feature enables you to categorize the cell for analysis. For example, you can format a time sheet, to point out the overtime obtained by an employee. You can also use it to track the best sales employees in the company, by setting a quota that makes a cell range particular.

Defining Condition for Spreadsheet Cells

You can define the condition for formatting the Spreadsheet cells using a conditional formatting dialog box. Specify the conditional value and style format in the dialog box. You can open the conditional formatting dialog using the ConditionalFormatCommand. Based on the Command parameter one of the following dialogs will open:

  • Greater than

Formatting_img1

  • Less Than

Formatting_img2

  • Between

Formatting_img3

  • Equal to

Formatting_img4

The following code illustrates how to bind the ConditionalFormatCommand to a button:

  • XAML
  • <Button Command="{Binding Path=ConditionalFormatCommand}">
    
    	<Button.CommandParameter>
    
    		<XlsIO:ExcelComparisonOperator>Greater</XlsIO:ExcelComparisonOperator>
    
    	</Button.CommandParameter>
    
    </Button>

    Formatting_img5

    Number formatting

    Number formatting helps you to control the format of the number in Spreadsheet cells. Number in the cell will be displayed based on the number format applied.

    Defining number formatting for Spreadsheet Cells

    You can define the number formatting using the NumberFormattingCommand. Number formatting will be applied to the Spreadsheet cells based on the command parameter. The following code illustrates this:

  • XAML
  • <Button Command="{Binding Path=NumberFormatCommand}" Grid.Row="2">
    
    	<Button.CommandParameter>
    
    		<System:String>0.00%</System:String>
    
    	</Button.CommandParameter>
    
    </Button>

    Formatting_img6

    Center Across Selection

    Overview

    This feature center aligns the cell value in Spreadsheet, across the range of selected cells.

    Formatting_img7

    Properties, Methods and Events

    Methods

    Method Description Parameters Type Return Type
    SetCenterAcrossSelection() This method sets the Center Across Selection on the selected cells. It should be explicitly called to set Center Across Selection. setCenterAcrossSelection() null void

    Center aligning cell values in Spreadsheet

    The following code snippets manually set the center across selection by calling the method:

    SpreadsheetControl.GridProperties.CurrentExcelGridModel.setCenterAcrossSelection();
    SpreadsheetControl.GridProperties.CurrentExcelGridModel.setCenterAcrossSelection()

    The following code snippet manually sets the center across selection by calling the command:

  • XAML
  • <Button Content="CentreAcrossSelection" Margin="5" Width="200" Command="{Binding ElementName=spreadSheetControl, Path=CenterAcrossSelectionCommand}"/>

    The output displayed is shown in the following screenshot:

    Formatting_img8