Back to Devexpress

Formatting.Font Property

officefileapi-devexpress-dot-spreadsheet-dot-formatting-c5881527.md

latest9.2 KB
Original Source

Formatting.Font Property

Provides access to the cell font.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
SpreadsheetFont Font { get; }
vb
ReadOnly Property Font As SpreadsheetFont

Property Value

TypeDescription
SpreadsheetFont

A SpreadsheetFont object providing properties to change cell font attributes.

|

Remarks

For details on how to set different characteristics of a cell font, see the How to: Configure Cell Font Settings 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)

The following code snippets (auto-collected from DevExpress Examples) contain references to the Font property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/SpreadsheetActions/FormattingActions.cs#L392

csharp
// Access the Font object.
SpreadsheetFont cellFont = worksheet.Cells["A1"].Font;
// Set the font name.

winforms-spreadsheet-custom-draw-example/CS/WindowsFormsApp1/Form1.cs#L143

csharp
// Specify font attributes for the column header.
SpreadsheetFont defaultFont = spreadsheetControl1.Document.Styles.DefaultStyle.Font;
using (Font font = new Font(defaultFont.Name, (float)defaultFont.Size, FontStyle.Bold))

wpf-spreadsheetcontrol-api-part-1/CS/SpreadsheetControl_WPF_API/SpreadsheetActions/FormattingActions.cs#L361

csharp
// Access the Font object.
SpreadsheetFont cellFont = worksheet.Cells["A1"].Font;
// Set the font name.

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/FormattingActions.cs#L252

csharp
// Access the Font object.
SpreadsheetFont cellFont = worksheet.Cells["A1"].Font;
// Specify the font name.

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/FormattingActions.vb#L380

vb
' Access the Font object.
Dim cellFont As SpreadsheetFont = worksheet.Cells("A1").Font
' Set the font name.

winforms-spreadsheet-custom-draw-example/VB/CustomDrawExample/Form1.vb#L41

vb
' Specify font attributes for the column header.
Dim defaultFont As SpreadsheetFont = spreadsheetControl1.Document.Styles.DefaultStyle.Font
Using font As New Font(defaultFont.Name, CSng(defaultFont.Size), FontStyle.Bold)

wpf-spreadsheetcontrol-api-part-1/VB/SpreadsheetControl_WPF_API/SpreadsheetActions/FormattingActions.vb#L348

vb
' Access the Font object.
Dim cellFont As SpreadsheetFont = worksheet.Cells("A1").Font
' Set the font name.

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/FormattingActions.vb#L204

vb
' Access the Font object.
Dim cellFont As SpreadsheetFont = worksheet.Cells("A1").Font
' Specify the font name.

See Also

How to: Clear Cell Formatting

Formatting Interface

Formatting Members

DevExpress.Spreadsheet Namespace