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 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);

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.

Like it?

Download Buy

If you want to try the GemBox.Spreadsheet for Java yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.