facebooktwittermenuarrow-up

GemBox Support Forum

Get cell formatted as html

I’m trying to import an excel sheet. The excel sheet is formatted with mixed colors and fonts in the cell. I’d like to be able to extract the cell value as html. So it could be displayed in a web page with the formatting. Is there any way to do this with Gembox?

There is no built-in solution for this, but you can do the following:

  1. Set the print area to the cell you want to export by using the ExcelWorksheet.NamedRanges.SetPrintArea method.
    sheet.NamedRanges.SetPrintArea(sheet.Cells["A1"].ToRange());
  2. Save the ExcelFile as an HTML table. For that you need to set the HtmlType to HtmlTable.
    workbook.Save("Output.html", new HtmlSaveOptions() { HtmlType = HtmlType.HtmlTable });

That will create an HTML file with a single-cell table in it. The HTML representation of the cell’s value will be within the <td> element.