Back to Devexpress

Cell.GetHtmlContent(HtmlCellContentExportOptions) Method

officefileapi-devexpress-dot-spreadsheet-dot-cell-dot-gethtmlcontent-x28-devexpress-dot-xtraspreadsheet-dot-export-dot-htmlcellcontentexportoptions-x29.md

latest4.3 KB
Original Source

Cell.GetHtmlContent(HtmlCellContentExportOptions) Method

Gets cell content as a string in HTML format. Allows you to specify export options.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
string GetHtmlContent(
    HtmlCellContentExportOptions options
)
vb
Function GetHtmlContent(
    options As HtmlCellContentExportOptions
) As String

Parameters

NameTypeDescription
optionsHtmlCellContentExportOptions

A HtmlCellContentExportOptions object that contains export options.

|

Returns

TypeDescription
String

The string that contains cell content in HTML format.

|

Remarks

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

You can specify the following options:

IgnoreDisplayFormatGets or sets whether to ignore the display format when exporting cell content to HTML.FontUnitGets or sets the measurement unit to specify font size when exporting to HTML.

Example

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.

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[4, 1]; //B3
    HtmlCellContentExportOptions htmlExportOptions = new HtmlCellContentExportOptions();
    htmlExportOptions.IgnoreDisplayFormat = true;
    htmlExportOptions.FontUnit = DevExpress.XtraSpreadsheet.Export.Html.HtmlFontUnit.Pixel;
    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(4, 1) 'B3
    Dim htmlExportOptions As New HtmlCellContentExportOptions()
    htmlExportOptions.IgnoreDisplayFormat = True
    htmlExportOptions.FontUnit = DevExpress.XtraSpreadsheet.Export.Html.HtmlFontUnit.Pixel
    Dim htmlContentString As String = cell.GetHtmlContent(htmlExportOptions)

End Using

The resulting HTML string looks as follows:

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

See Also

Export Cell Content from Spreadsheet Documents

Cell Interface

Cell Members

DevExpress.Spreadsheet Namespace