Skip to main content
All docs
V23.2

Export Cell Content from Spreadsheet Documents

  • 3 minutes to read

You can use the Spreadsheet API to export cell content to HTML and RTF.

Export to HTML

Use the following API to export cell content to HTML and specify export options:

GetHtmlContent()
Gets cell content as a string in HTML format.
GetHtmlContent(HtmlCellContentExportOptions)
Gets cell content as a string in HTML format. Allows you to specify export options.
HtmlCellContentExportOptions
Contains options for cell content export to HTML.
FontUnit
Gets or sets the measurement units used for the font size when exporting cell content to HTML.
IgnoreDisplayFormat
Gets or sets whether to ignore the display format when exporting cell content to HTML.

The following snippet loads a document from a file and exports content from cell B3. The IgnoreDisplayFormat property is set to true and the FontUnit property is set to Pixel. The cell contains conditional formatting.

using DevExpress.Spreadsheet;
using DevExpress.XtraSpreadsheet.Export;
//... 

spreadsheetControl1.LoadDocument("Documents\Document.xlsx", DocumentFormat.Xlsx);
IWorkbook workbook = spreadsheetControl1.Document;

Worksheet worksheet = workbook.Worksheets[0];
Cell cell = worksheet[4, 1]; //B3
HtmlCellContentExportOptions htmlExportOptions = new HtmlCellContentExportOptions();
htmlExportOptions.IgnoreDisplayFormat = true;
htmlExportOptions.FontUnit = DevExpress.XtraSpreadsheet.Export.Html.HtmlFontUnit.Pixel;
string htmlContentString = cell.GetHtmlContent(htmlExportOptions);

//...

Spreadsheet - Conditional Formatting

The resulting HTML string looks as follows:

<font style="font-family:Calibri;font-size:15px;font-weight:normal;font-style:normal;color:#FFFFFF;">cell with conditional formatting</font>

Export to RTF

Use the following API to export cell content to RTF and specify export options:

GetRtfContent()
Gets cell content as a string in RTF format.
GetRtfContent(RtfCellContentExportOptions)
Gets cell content as a string in RTF format. Allows you to specify export options.
RtfCellContentExportOptions
Contains options for cell content export to RTF.
IgnoreDisplayFormat
Gets or sets whether to ignore the display format when exporting cell content to RTF.

The following snippet loads a document from a file and exports content from cell B3. The IgnoreDisplayFormat property is set to true:

using DevExpress.Spreadsheet;
using DevExpress.XtraSpreadsheet.Export;
//... 

spreadsheetControl1.LoadDocument("Documents\Document.xlsx", DocumentFormat.Xlsx);
IWorkbook workbook = spreadsheetControl1.Document;
Worksheet worksheet = workbook.Worksheets[0];

Cell cell = worksheet[4, 1]; //B3
RtfCellContentExportOptions rtfExportOptions = new RtfCellContentExportOptions();
rtfExportOptions.IgnoreDisplayFormat = true;
string rtfContentString = cell.GetRtfContent(rtfExportOptions);

//...

Spreadsheet - Conditional Formatting

The resulting HTML string looks as follows:

{\rtf1\deff0{\fonttbl{\f0 Calibri;}}{\colortbl;}{\fs22 cell with conditional formatting}}