Back to Devexpress

Formatting Interface

officefileapi-devexpress-dot-spreadsheet-2914dac4.md

latest7.1 KB
Original Source

Formatting Interface

Provides access to cell format characteristics.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public interface Formatting
vb
Public Interface Formatting

The following members return Formatting objects:

Remarks

The Formatting interface provides properties to change cell format settings (Formatting.Alignment, Formatting.Borders, Formatting.Fill, Formatting.Font, Formatting.NumberFormat, etc.). The CellRange and Style interfaces are inherited from the Formatting interface, so you can use all these properties to perform direct cell formatting and create styles to apply a predefined set of format attributes to multiple cells.

  • To format an individual cell, use the cell’s properties that are inherited from the Formatting interface directly.
  • To format a cell range, modify the Formatting object within the CellRange.BeginUpdateFormatting - CellRange.EndUpdateFormatting method pair.
  • To share the same format settings between multiple cells in one step, apply the style with the specified format characteristics to the required cells. Access the Style object from the IWorkbook.Styles collection and modify the style’s properties inherited from the Formatting interface within the Formatting.BeginUpdate-Formatting.EndUpdate paired methods.

For more information, see the Formatting Cells document and the Formatting Cells section of examples.

Example

This example demonstrates how to format cells in a worksheet.

View Example

csharp
// Access the cell to be formatted.
Cell cell = worksheet.Cells["B2"];

// Specify font settings (font name, color, size and style).
cell.Font.Name = "MV Boli";
cell.Font.Color = Color.Blue;
cell.Font.Size = 14;
cell.Font.FontStyle = SpreadsheetFontStyle.Bold;

// Specify cell background color.
cell.Fill.BackgroundColor = Color.LightSkyBlue;

// Specify text alignment in the cell. 
cell.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
cell.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
// Access the range of cells to be formatted.
CellRange range = worksheet.Range["C3:E6"];

// Begin updating of the range formatting. 
Formatting rangeFormatting = range.BeginUpdateFormatting();

// Specify font settings (font name, color, size and style).
rangeFormatting.Font.Name = "MV Boli";
rangeFormatting.Font.Color = Color.Blue;
rangeFormatting.Font.Size = 14;
rangeFormatting.Font.FontStyle = SpreadsheetFontStyle.Bold;

// Specify cell background color.
rangeFormatting.Fill.BackgroundColor = Color.LightSkyBlue;

// Specify text alignment in cells.
rangeFormatting.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
rangeFormatting.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;

// End updating of the range formatting.
range.EndUpdateFormatting(rangeFormatting);
vb
' Access the cell to be formatted.
Dim cell As Cell = worksheet.Cells("B2")

' Specify font settings (font name, color, size and style).
cell.Font.Name = "MV Boli"
cell.Font.Color = Color.Blue
cell.Font.Size = 14
cell.Font.FontStyle = SpreadsheetFontStyle.Bold

' Specify cell background color.
cell.Fill.BackgroundColor = Color.LightSkyBlue

' Specify text alignment in the cell. 
cell.Alignment.Vertical = SpreadsheetVerticalAlignment.Center
cell.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center
' Access the range of cells to be formatted.
Dim range As CellRange = worksheet.Range("C3:E6")

' Begin updating of the range formatting. 
Dim rangeFormatting As Formatting = range.BeginUpdateFormatting()

' Specify font settings (font name, color, size and style).
rangeFormatting.Font.Name = "MV Boli"
rangeFormatting.Font.Color = Color.Blue
rangeFormatting.Font.Size = 14
rangeFormatting.Font.FontStyle = SpreadsheetFontStyle.Bold

' Specify cell background color.
rangeFormatting.Fill.BackgroundColor = Color.LightSkyBlue

' Specify text alignment in cells.
rangeFormatting.Alignment.Vertical = SpreadsheetVerticalAlignment.Center
rangeFormatting.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center

' End updating of the range formatting.
range.EndUpdateFormatting(rangeFormatting)

See Also

Formatting Members

DevExpress.Spreadsheet Namespace