IXlCell.SetRichText(XlRichTextString) Method
Assigns the rich formatted text to a cell.
Namespace: DevExpress.Export.Xl
Assembly: DevExpress.Printing.v24.1.Core.dll
NuGet Package: DevExpress.Printing.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
value | XlRichTextString | An XlRichTextString object that is a combination of specifically formatted text regions. |
Remarks
Use the SetRichText method to add the rich formatted text to a cell. Such rich text is defined by the XlRichTextString object and represents a cell text divided into separate regions (so-called text runs), each of which has its own set of font characteristics. Each text region is defined by the XlRichTextRun object and is stored in the collection of runs accessible from the XlRichTextString.Runs property.
To apply different fonts to specific regions of the cell text, create an instance of the XlRichTextString class, add the required number of XlRichTextRun objects to the XlRichTextString.Runs collection, and then pass the specified XlRichTextString instance to the SetRichText method as a parameter. For more information, refer to the How to: Apply Rich Formatting to the Cell Text example.
Example
Note
A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples
// Create a new worksheet.
using (IXlSheet sheet = document.CreateSheet())
{
// Create the first column and set its width.
using (IXlColumn column = sheet.CreateColumn())
{
column.WidthInPixels = 180;
}
// Create the first row.
using (IXlRow row = sheet.CreateRow())
{
// Create the cell A1.
using (IXlCell cell = row.CreateCell())
{
// Create an XlRichTextString instance.
XlRichTextString richText = new XlRichTextString();
// Add three text runs to the collection.
richText.Runs.Add(new XlRichTextRun("Formatted ", XlFont.CustomFont("Arial", 14.0, XlColor.FromArgb(0x53, 0xbb, 0xf4))));
richText.Runs.Add(new XlRichTextRun("cell ", XlFont.CustomFont("Century Gothic", 14.0, XlColor.FromArgb(0xf1, 0x77, 0x00))));
richText.Runs.Add(new XlRichTextRun("text", XlFont.CustomFont("Consolas", 14.0, XlColor.FromArgb(0xe3, 0x2c, 0x2e))));
// Add the rich formatted text to the cell.
cell.SetRichText(richText);
}
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SetRichText(XlRichTextString) method.
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.