[Expand]General Information
[Expand]WinForms Controls
[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
[Collapse]Office File API
  Demo Application
  Redistribution and Deployment
 [Collapse]Spreadsheet Document API
   Product Structure
   Getting Started
  [Expand]Spreadsheet Document
   Supported Formats
  [Expand]Cell Basics
  [Expand]Spreadsheet Formulas
   Defined Names
   Data Binding
  [Expand]Pivot Tables
  [Expand]Shapes, Pictures, Charts
  [Expand]Mail Merge
  [Collapse]Examples
   [Expand]Files
   [Expand]Workbooks
   [Expand]Worksheets
   [Expand]Rows and Columns
   [Expand]Cells
   [Expand]Formulas
   [Expand]Import and Export Data
   [Expand]Data Binding
    Sorting
   [Expand]Mail Merge
    Search
   [Expand]Shapes
   [Expand]Charts
   [Expand]Sparklines
   [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: 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]Grouping
   [Expand]Filtering
   [Expand]Tables
   [Expand]Pivot Tables
   [Expand]Printing
   [Expand]Pictures
   [Expand]Protection
 [Expand]Word Processing Document API
 [Expand]PDF Document API
 [Expand]Excel Export Library
 [Expand]Snap Report API
 [Expand]Zip Compression and Archive API
 [Expand]Barcode Generation API
 [Expand]Unit Conversion API
 [Expand]API Reference
[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

This topic demonstrates how to apply rich formatting to text values within a cell.

Important

At present, rich formatting is lost when you print or export a workbook to PDF. However, rich text is saved to a file, so you can use Microsoft® Excel® or another spreadsheet application to view and print a document.

A RichTextString class defines rich formatted text within a cell. 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.

Range.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

Range.HasRichText

Checks whether a cell contains rich formatted text.

Range.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 Range.Value property to obtain the resulting text string as plain text.

RichTextString.Length

Returns the rich text length.

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