Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Export a Document to HTML

  • 2 minutes to read

The example below demonstrates how to save a worksheet and a cell range as HTML files using the IWorkbook.ExportToHtml method overloads. To specify export options, create an instance of the HtmlDocumentExporterOptions class and pass it as a parameter to the ExportToHtml method.

View Example

workbook.LoadDocument("Documents\\ExpenseReport.xlsx");
workbook.Calculate();
Worksheet worksheet = workbook.Worksheets[0];

// Create an object containing HTML export options.
HtmlDocumentExporterOptions options = new HtmlDocumentExporterOptions();

// Set HTML-specific export options.
options.CssPropertiesExportType = DevExpress.XtraSpreadsheet.Export.Html.CssPropertiesExportType.Style;
options.Encoding = Encoding.UTF8;

// Specify the part of the document to be exported to HTML.
options.SheetIndex = worksheet.Index;
options.Range = "B11:O28";

// Export a document to an HTML file with the specified options.
workbook.ExportToHtml("OutputRange.html", options);

// Export the entire worksheet to a stream as HTML.
FileStream htmlStream = new FileStream("OutputWorksheet.html", FileMode.Create);
workbook.ExportToHtml(htmlStream, worksheet.Index);