Rich Text Formatting

This module uses the DevExpress Spreadsheet API to create rich text formatting in cells. Rich text allows you to format parts of text within a single cell.

Use text boxes to enter cell text in three parts. In the Formatting Settings section, select a color for each part. The module will populate a cell with rich-formatted text according to your input.

Use the Apply Formatting and Save as ... dropdown button to select an output format, generate a document with formatted text, and download the result.




using DevExpress.Spreadsheet;
using System.Drawing;

async Task<Stream> CreateWorkbookWithRichTextFormatting(Stream inputStream, string firstTextPart, string secondTextPart,
    string thirdTextPart, Color firstPartColor, Color secondPartColor, Color thirdPartColor, DocumentFormat outputFormat) {
    using Workbook workbook = new Workbook();

    workbook.BeginUpdate();
    try {
        // Use the first worksheet
        Worksheet worksheet = workbook.Worksheets.First();
        worksheet.Name = "Rich Text Formatting";

        // Create a RichTextString instance
        RichTextString richText = new RichTextString();

        // Add three text runs. Each run has its own font settings
        richText.AddTextRun(firstTextPart + " ", new RichTextRunFont("Arial", 14, firstPartColor));
        richText.AddTextRun(secondTextPart + " ", new RichTextRunFont("Tahoma", 14, secondPartColor));
        richText.AddTextRun(thirdTextPart, new RichTextRunFont("Castellar", 14, thirdPartColor));

        // Assign the rich formatted text to the cell A1
        worksheet["A1"].SetRichText(richText);
    }
    finally {
        workbook.EndUpdate();
    }

    // Create output stream
    Stream outputStream = new MemoryStream();

    // Save document in target format
    await workbook.SaveDocumentAsync(outputStream, outputFormat);

    outputStream.Seek(0, SeekOrigin.Begin);
    return outputStream;
}