Back to Devexpress

Formatting.Alignment Property

officefileapi-devexpress-dot-spreadsheet-dot-formatting-1ebee359.md

latest5.2 KB
Original Source

Formatting.Alignment Property

Provides access to cell alignment.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
Alignment Alignment { get; }
vb
ReadOnly Property Alignment As Alignment

Property Value

TypeDescription
Alignment

An Alignment object providing properties to specify cell alignment settings.

|

Remarks

For details on how to set different characteristics of cell alignment, see the How to: Align Cell Content example.

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

How to: Clear Cell Formatting

Formatting Interface

Formatting Members

DevExpress.Spreadsheet Namespace