Back to Devexpress

Cell.GetHtmlContent() Method

officefileapi-devexpress-dot-spreadsheet-dot-cell-c4992b39.md

latest2.7 KB
Original Source

Cell.GetHtmlContent() Method

Gets cell content as a string in HTML format.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
string GetHtmlContent()
vb
Function GetHtmlContent As String

Returns

TypeDescription
String

The string that contains cell content in HTML format.

|

Remarks

Use the GetHtmlContent method to export cell content to HTML and obtain the result as a string.

Example

The following snippet loads a document from a file and exports content from cell B2. The cell contains rich-formatted text with 3 text runs.

cs
using DevExpress.Spreadsheet;
using DevExpress.XtraSpreadsheet.Export;
//... 
using (Workbook workbook = new Workbook()) {
    workbook.LoadDocument("Documents\\Document.xlsx", DocumentFormat.Xlsx);
    workbook.Calculate();

    Worksheet worksheet = workbook.Worksheets[0];
    Cell cell = worksheet[3, 1]; //B2
    string htmlContentString = cell.GetHtmlContent(htmlExportOptions);
}
vb
Imports DevExpress.Spreadsheet
Imports DevExpress.XtraSpreadsheet.Export
'... 
Using workbook As New Workbook()
    workbook.LoadDocument("Documents\Document.xlsx", DocumentFormat.Xlsx)
    workbook.Calculate()

    Dim worksheet As Worksheet = workbook.Worksheets(0)
    Dim cell As Cell = worksheet(3, 1) 'B2
    Dim htmlContentString As String = cell.GetHtmlContent(htmlExportOptions)
End Using

The resulting HTML string looks as follows:

ets
<font style="font-family:Arial;font-size:14pt;font-weight:normal;font-style:normal;color:#C59FC9;">Rich </font>
<font style="font-family:Tahoma;font-size:14pt;font-weight:normal;font-style:normal;color:#2C608E;">text </font>
<font style="font-family:Castellar;font-size:14pt;font-weight:normal;font-style:normal;color:#2F244F;">formatting</font>

See Also

Export Cell Content from Spreadsheet Documents

Cell Interface

Cell Members

DevExpress.Spreadsheet Namespace