EasyXLS

Rich text format in cell

EasyXLS™ library allows you to import or export rich text format in the cells of an Excel file, by means of HTML syntax when setting the value for the cell.

The following tags are supported:
<b>
<strong>
<i>
<u>
<s>
<strike>
<sup>
<sub>
<font color= face= size=>
The above tags have the same meaning as in HTML.

In order to set the underline style for a group of characters EasyXLS uses four specific tags:
<underline single>
<underline double>
<underline single-accounting>
<underline double-accounting>

Source code sample

The below example shows how to export rich text format (RTF) in an Excel cell.

C#.NET
VB.NET
C++
Java
PHP
ASP
VB6
VBS
Coldfusion
Python

// Create an instance of the class that exports Excel files, having two sheets
ExcelDocument workbook = new ExcelDocument(2);

// Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab");
workbook.easy_getSheetAt(1).setSheetName("Second tab");

// Get the table of data for the first worksheet
ExcelTable xlsFirstTable = 
        ((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable();

// Create the string used to set the RTF in cell
String sRTFValue = "This is <b>bold</b>.";
sRTFValue += "\nThis is <i>italic</i>.";
sRTFValue += "\nThis is <u>underline</u>.";
sRTFValue += "\nThis is <underline double>double underline</underline double>.";
sRTFValue += "\nThis is <font color=red>red</font>.";
sRTFValue += "\nThis is <font color=rgb(255,0,0)>red</font> too.";
sRTFValue += "\nThis is <font face=\"Arial Black\">Arial Black</font>.";
sRTFValue += "\nThis is <font size=15pt>size 15</font>.";
sRTFValue += "\nThis is <s>strikethrough&glt;/s>.";
sRTFValue += "\nThis is <sup>superscript&glt;/sup>.";
sRTFValue += "\nThis is <sub>subscript</sub>.";
sRTFValue += "\n<b>This</b><i>is</i><font color=red face=\"Arial Black\" size=15pt>" + 
"<underline double>formatted</underline double></font><s>text</s>.";

// Set the rich text value
xlsFirstTable.easy_getCell(1, 0).setHTMLValue(sRTFValue); 
...

// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Rich text format.xlsx");

     Click here to see Continuous Code Listing

The screen shot below represents the exported Excel file with rich text in cell generated by the code sample above.

Exported Excel file with rich text format in cell


Available for: Professional, Excel Writer, Excel Reader
Go to top

EasyXLS Excel libraries:

.NET
.NET Excel Library
full .NET version to import, export or convert Excel files
COM+ Excel Library
full COM+ version to import, export or convert Excel files
-
Java
Java Excel Library
full Java version to import, export or convert Excel files
Download EasyXLS™ Excel Library for .NET and Java

File formats:

Office 365
MS Excel 2021 - 2025
MS Excel 2007 - 2019
MS Excel 97 - 2003
XLSXXLSMXLSBXLS
XMLHTMLCSVTXT