Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Collapse]Spreadsheet
   [Expand]Product Information
    Product Structure
    Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Collapse]Cell Basics
     Cell Data Types
     Dates and Times in Cells
     Error Types
     Cell Referencing
     Formatting Cells
   [Expand]Spreadsheet Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
    Data Grouping
   [Expand]Pivot Table Overview
   [Expand]Charting Overview
    Printing
    Events
   [Expand]Mail Merge Overview
    Protection
    Find and Replace
   [Expand]Visual Elements
    Services
   [Expand]Shortcuts
   [Expand]Examples
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Formatting Cells

The proper formatting of worksheet cells improves document appearance, and allows end-users to read, find and understand data more easily. Cell formatting includes a variety of features such as multiple settings for font, font size, character style (bold, italics, underlined), text alignment, background and foreground colors, etc. This document explains the concepts of Cell Styles, Direct Cell Formatting and Style Flags, and provides an overview of the Custom Draw feature, as well as links to Examples on how to format cells programmatically.

For detailed information on conditional formatting, see the Conditional Formatting topic and the Examples section .

Expanded Cell Styles

A style is a named set of predefined cell format characteristics (font settings, number format, content alignment, cell borders, fill color, etc.). When applying a style, all format settings are applied to a cell or cell range in a single step.

A workbook maintains all available styles in a StyleCollection collection, which is accessed via the IWorkbook.Styles property. By default, this collection contains a set of built-in cell styles similar to Microsoft® Excel® (including the Normal style, which is applied to all unformatted cells in the workbook by default). Identifiers of all built-in styles are listed by the DevExpress.Spreadsheet.BuiltInStyleId enumerator.

You can do the following to manage the workbook's collection of cell styles.

  • Modify an existing style by changing the properties of the corresponding Style object. Use the Formatting.BeginUpdate - Formatting.EndUpdate method pair to make multiple modifications to a style.

  • Create a new custom style by adding a new Style object to the IWorkbook.Styles collection. Note that by default, new styles are created based on the Normal style.

  • Duplicate an existing style by creating a new style and copying all format settings from the existing style via the Style.CopyFrom method.

For examples, see the How to: Create or Modify a Style document.

Note

All custom styles of an Excel document that is loaded to a SpreadsheetControl are automatically added to the IWorkbook.Styles collection, and can be accessed by their names.

To format a cell or cell range by applying a style, assign the required Style object to the Range.Style property. For details, see the How to: Apply a Style to a Cell or Range of Cells example.

Expanded Direct Cell Formatting

To change cell appearance, you can not only apply a style, but also set the required format characteristics directly for an individual cell or cell range. This is called direct cell formatting. In SpreadsheetControl, direct cell formatting options are available via the Ribbon interface (the Home tab) or in the Format Cells dialog.

To perform direct cell formatting programmatically, change the cell or cell range properties that are inherited from the Formatting interface (Formatting.Fill, Formatting.Font, Formatting.Alignment, Formatting.Borders and Formatting.NumberFormat). By default, these properties are set according to the style applied to the cell. Use the following approaches.

Thus, a Cell or Range object's properties inherited from the Formatting interface provide access to the actual formatting specified for a cell or range of cells (including characteristics defined by an applied style and direct cell formatting attributes).

Expanded Style Flags

As mentioned above, the appearance of a cell is determined by the format settings of the applied style and the format settings of the cell itself. Each of these formatting types provides a set of flags (Formatting.Flags). Each flag corresponds to a specific group of format attributes, and indicates whether to use the attributes specified in the applied style or the attributes specified directly for the cell.

Group

Attributes

Flag

Alignment Horizontal and vertical alignment of cell content, indentation and text wrap. StyleFlags.Alignment
Borders Cell border line styles and colors. StyleFlags.Borders
Fill Cell background color. StyleFlags.Fill
Font Cell font settings (name, style, color and size). StyleFlags.Font
Number Format Cell number format. StyleFlags.Number
Protection Cell protection options (Locked and Hidden). StyleFlags.Protection

Expanded Custom Draw

SpreadsheetControl provides the SpreadsheetControl.CustomDrawCell and SpreadsheetControl.CustomDrawCellBackground events, which you can handle to custom paint worksheet cells. For example, the following image demonstrates how the custom draw feature can be used to display callouts for cells.

Expanded Examples

Expanded See Also

How would you rate this topic?​​​​​​​