Skip to main content

Command Palette

Search for a command to run...

Quick Guide: Convert Excel to HTML with Java

Updated
2 min read
Quick Guide: Convert Excel to HTML with Java

Many web applications need to display Excel reports directly in the browser — for online preview, embedding in dashboards, or sharing interactive reports. This guide explains how to convert Excel (.xls / .xlsx) files to HTML in Java using the free Free Spire.XLS for Java library, and covers options for converting an entire workbook or exporting individual worksheets (including embedding images as Base64) so the output is browser-ready and easy to integrate into web UIs.


1. Setting Up the Library

Add the following Maven repository and dependency to your pom.xml:

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls.free</artifactId>
        <version>16.3.1</version>
    </dependency>
</dependencies>

2. Convert an Entire Workbook to HTML

The following code loads an Excel file (.xls or .xlsx) and saves the entire workbook as a single HTML file.

import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;

public class FullWorkbookConversion {
    public static void main(String[] args) {
        Workbook workbook = new Workbook();
        workbook.loadFromFile("sample.xlsx");

        workbook.saveToFile("output/full_workbook.html", FileFormat.HTML);
        System.out.println("Conversion completed.");
    }
}

3. Convert a Specific Worksheet with Embedded Images

If you need only one sheet and want images to be embedded directly into the HTML (as Base64), use the Worksheet class together with HTMLOptions.

import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
import com.spire.xls.core.spreadsheet.HTMLOptions;

public class SingleSheetConversion {
    public static void main(String[] args) {
        Workbook workbook = new Workbook();
        workbook.loadFromFile("product.xlsx");

        // Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        // Enable image embedding
        HTMLOptions options = new HTMLOptions();
        options.setImageEmbedded(true);

        // Save the worksheet as HTML
        sheet.saveToHtml("output/single_sheet.html", options);
        System.out.println("Worksheet converted with embedded images.");
    }
}

Setting setImageEmbedded(true) encodes pictures and charts directly into the HTML, making the file completely self-contained.


4. Troubleshooting Common Issues

Problem Possible Solution
Fonts look wrong The HTML uses the browser's font rendering. Install common fonts (e.g., Liberation) on the server or specify fallback fonts in CSS.
Images missing Verify that images are embedded objects (not linked) and that setImageEmbedded(true) is applied.
HTML file too large Filter or split the Excel data before conversion. The free version has a 100‑row limit per worksheet, which helps keep file sizes manageable.
Free version limitations Note the free edition limitations while conversion.