[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
  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]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [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
   [Expand]Cell Basics
   [Expand]Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
    Data Grouping
   [Expand]Pivot Tables
   [Expand]Charts and Graphics
    Printing
    Events
   [Expand]Mail Merge
    Protection
    Operation Restrictions
    Find and Replace
   [Expand]Visual Elements
    Services
   [Expand]Keyboard Shortcuts
   [Collapse]Examples
    [Expand]Files
    [Expand]Workbooks
    [Expand]Worksheets
    [Expand]Rows and Columns
    [Expand]Cells
    [Expand]Formulas
    [Expand]Import and Export Data
    [Expand]Data Binding
    [Expand]Mail Merge
    [Collapse]Formatting Cells
      How to: Apply a Style to a Cell or Range of Cells
      How to: Create or Modify a Style
      How to: Format a Cell or Range of Cells
      How to: Apply Rich Formatting to Cell Text
      How to: Specify Number or Date Format for Cell Content
      How to: Change Cell Font and Background Color
      How to: Apply Gradient Fill
      How to: Configure Cell Font Settings
      How to: Align Cell Content
      How to: Add and Remove Cell Borders
      How to: Clear Cell Formatting
    [Expand]Conditional Formatting
    [Expand]Group Data
    [Expand]Filter Data
    [Expand]Shapes
    [Expand]Tables
    [Expand]Pivot Tables
    [Expand]Printing
    [Expand]Pictures
    [Expand]Charts
    [Expand]Sparklines
    [Expand]Protection
    [Expand]Commands
    [Expand]Customization
  [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]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Apply Rich Formatting to Cell Text

The RichTextString class provides the means to format text values within spreadsheet cells. Rich text consists of one or more text regions (or text runs), each with its own set of font characteristics. The RichTextString.Runs property provides access to a collection of text runs. A RichTextRun object represents an individual run within a collection.

Expanded Create Rich Text

Use the following members to apply rich formatting to the cell's text.

Member

Description

RichTextString.AddTextRun

Adds a new text run with the specified font settings to the rich text string.

RichTextString.Characters

Allows you to format specific characters within the cell's text.

RichTextRange.SetFont/

RichTextRange.Font

Allows you to specify font attributes for specific characters within the cell's text.

RichTextString.Text

Gets or sets the full text displayed in a cell.

CellRange.SetRichText

Assigns rich formatted text to a cell.

  • Example I

    The following code snippet uses the RichTextString.AddTextRun method to compose the cell's text from individual text runs.

  • Example II

    The code snippet below uses the RichTextString.Characters method to format a portion of the cell's text.

Expanded Access Rich Text

CellRange.HasRichText

Checks whether a cell contains rich formatted text.

CellRange.GetRichText

Retrieves rich text from a cell.

RichTextString.Runs

Allows you to iterate through a collection of the existing text runs.

RichTextRun.Text

Gets the current run's text.

RichTextRun.Font

Gets font attributes applied to the current run.

Expanded Format Characters within an Existing Text

The following example shows how to apply rich formatting to a cell that already contains a text value.

Expanded Obtain the Entire Rich Text String and Its Length

RichTextString.Text

Gets or sets the full text contained in a cell.

You can also use the cell's CellRange.Value property to obtain the resulting text string as plain text.

RichTextString.Length

Returns the rich text length.

Is this topic helpful?​​​​​​​