private static void ExportToHTML(IWorkbook workbook) { #region #ExportToHTML 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); #endregion #ExportToHTML System.Diagnostics.Process.Start("OutputRange.html"); System.Diagnostics.Process.Start("OutputWorksheet.html"); }
private void btn_HTML_Click(object sender, EventArgs e) { FileStream htmlStream = new FileStream("OutputWorksheet.html", FileMode.Create); workbook.ExportToHtml(htmlStream, worksheet.Index); MessageBox.Show("Your solution has been saved as HTML."); }
protected virtual string GenerateTableHtml(SpreadTableOptions options) { string htmlTable; IWorkbook workbook = null; bool disposeWorkbook = false; try { if (options._Spreadsheet != null) { workbook = options._Spreadsheet.Workbook; } else if (!string.IsNullOrWhiteSpace(options._FileName)) { disposeWorkbook = true; string fileName = Project.Current.MapPath(options._FileName); if (!File.Exists(fileName)) { throw new Exception($"File '{fileName}' does not exist."); } workbook = SpreadsheetUtils.CreateWorkbook(); workbook.LoadDocument(fileName); } else { workbook = Host?.Spreadsheet?.Workbook; } if (workbook == null) { throw new Exception("Spreadsheet is not specified"); } var range = SpreadsheetUtils.GetWorkbookRange(workbook, options._TableName); var optionsHtml = new DevExpress.XtraSpreadsheet.Export.HtmlDocumentExporterOptions() { SheetIndex = workbook.Sheets.IndexOf(range.Worksheet), Range = range.GetReferenceA1(), Encoding = Encoding.Unicode }; using var stream = new MemoryStream(); workbook.ExportToHtml(stream, optionsHtml); stream.Seek(0, SeekOrigin.Begin); using var reader = new StreamReader(stream, Encoding.UTF8); htmlTable = reader.ReadToEnd(); } finally { if (disposeWorkbook) { workbook?.Dispose(); } } return(htmlTable); }