Convert Excel files to HTML in Java

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.

HTML converted from Excel file with GemBox.Spreadsheet for Java
Screenshot of HTML converted from Excel file with GemBox.Spreadsheet for Java
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws {
        // If using the Professional version, put your serial key below.

        ExcelFile workbook = ExcelFile.load("%#HtmlExport.xlsx%");

        ExcelWorksheet worksheet = workbook.getWorksheet(0);

        // Some of the properties from ExcelPrintOptions class are supported in HTML export.

        // 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.setSelectionType(SelectionType.ENTIRE_FILE);"HtmlExport.html", options);

See also

Next steps

GemBox.Spreadsheet for Java is a component that enables you to read, write, edit and convert spreadsheet files from your applications using one simple API.

Download Buy