Convert Excel files to HTML in Java
GemBox.Spreadsheet for Java has been retired
GemBox.Spreadsheet for Java allows you to save an Excel workbook or worksheet in HTML or MHTML format.
The following example shows how you can convert an Excel file to HTML in Java.
Note the use of HtmlSaveOptions
to set the worksheet options that are supported when saving an Excel file in HTML format. The example shows saving of an entire Excel workbook and all its images in HTML format.
Since worksheet files must be physically saved on a disk, the following example cannot be run interactively from the Example Explorer.

import com.gembox.spreadsheet.*;
class Program {
public static void main(String[] args) throws java.io.IOException {
// If using the Professional version, put your serial key below.
SpreadsheetInfo.setLicense("FREE-LIMITED-KEY");
ExcelFile workbook = ExcelFile.load("%#HtmlExport.xlsx%");
ExcelWorksheet worksheet = workbook.getWorksheet(0);
// Some of the properties from ExcelPrintOptions class are supported in HTML export.
worksheet.getPrintOptions().setPrintHeadings(true);
worksheet.getPrintOptions().setPrintGridlines(true);
// Print area can be used to specify custom cell range which should be exported to HTML.
worksheet.getNamedRanges().setPrintArea(worksheet.getCells().getSubrange("A1", "J42"));
HtmlSaveOptions options = new HtmlSaveOptions();
options.setHtmlType(HtmlType.HTML);
options.setSelectionType(SelectionType.ENTIRE_FILE);
workbook.save("HtmlExport.html", options);
}
}
See also
Next steps
Published: December 13, 2018 | Modified: December 19, 2022 | Author: Marek Turis