Read Rich Text from an Excel Cell in C#, VB.NET

Using Spire.XLS, you're able to apply multiple fonts in a single cell in order to create rich-formatted text within the cell, you can also extract the formatted text from the cell(s) in an existing Excel document. The following code snippets will show you how to read rich text from an Excel cell in C# and VB.NET.

Step 1: Create a Workbook instance and load a sample Excel file.

Workbook wb = new Workbook();
wb.LoadFromFile(@"C:\Users\Administrator\Desktop\Sample.xlsx");

Step 2: Get the first worksheet.

Worksheet sheet= wb.Worksheets[0];

Step 3: Get the rtf text from the specified cell.

richTextBox1.Rtf = sheet.Range["B2"].RichText.RtfText;

Output:

Read Rich Text from an Excel Cell in C#, VB.NET

Full Code:

[C#]
private void btn_read_Click(object sender, EventArgs e)
{
    Workbook wb = new Workbook();
    wb.LoadFromFile(@"C:\Users\Administrator\Desktop\Sample.xlsx");
    Worksheet sheet= wb.Worksheets[0];
    richTextBox1.Rtf = sheet.Range["B2"].RichText.RtfText;
} 
[VB.NET]
Private  Sub btn_read_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim wb As Workbook =  New Workbook() 
    wb.LoadFromFile("C:\Users\Administrator\Desktop\Sample.xlsx")
    Dim sheet As Worksheet =  wb.Worksheets(0) 
    richTextBox1.Rtf = sheet.Range("B2").RichText.RtfText
End Sub