Font is wrong when converting Excel to HTML

When converting an excel file to html, the font is messed up.
In excel it looks like:
image.png (10.0 KB)

In the html preview it looks like:
image.png (5.7 KB)

We’re using aspose cells for java version 24.9.

I also included the excel file that has the issue:
Test.zip (8.1 KB)

@jtimmer

Issue

When converting the workbook to HTML the text is displayed with a different font than in the original Excel file.

Why it happens

Aspose Cells renders the workbook using the fonts that are available on the machine where the conversion runs.
If the exact font that is used in the worksheet (e.g., Calibri, Cambria, …) is not installed, Aspose Cells substitutes it with the closest available system font (by default Arial). The substituted font is what you see in the generated HTML.

How to fix it

1. Install the required fonts on the conversion server

The simplest solution is to make sure that every font referenced in the workbook is installed on the OS where the Java code executes.

Windows – copy the .ttf/.otf files to C:\Windows\Fonts (or use the Control Panel → Fonts).
Linux – copy the font files to /usr/share/fonts (or another directory) and run fc-cache -f -v.

2. Register a custom font folder for Aspose Cells (no OS‑level installation required)

If you cannot install the fonts system‑wide, you can tell Aspose Cells where to look for them.

import com.aspose.cells.*;

public class ExcelToHtml {
    public static void main(String[] args) throws Exception {
        // 1️⃣ Load the workbook
        Workbook wb = new Workbook("Test.xlsx");

        // 2️⃣ Register the folder that contains the missing fonts
        //    The second argument (true) tells Aspose to scan sub‑folders as well.
        FontConfigs.setFontFolder("C:/MyCustomFonts", true);

        // 3️⃣ Prepare HTML save options
        HtmlSaveOptions options = new HtmlSaveOptions();
        options.setExportActiveWorksheetOnly(true);   // optional – export only the active sheet
        options.setExportImagesAsBase64(true);        // embed images in the HTML
        // NOTE: Aspose Cells does **not** embed TrueType fonts into the HTML file.
        //       The font must be available on the client machine or registered via FontConfigs.

        // 4️⃣ Save as HTML
        wb.save("Test.html", options);
    }
}
  • Replace C:/MyCustomFonts with the path that contains all .ttf/.otf files used in the workbook (e.g., Calibri.ttf, Cambria.ttf, …).
  • The same code works on Linux/macOS – just use the appropriate path format.

3. Verify the HTML rendering

Open the generated Test.html in a browser that also has access to the required fonts (or copy the font files to the client machine). The text should now appear exactly as it does in Excel.

Additional tips

What you want to achieve Aspose Cells option / recommendation
Export only a specific sheet options.setExportActiveWorksheetOnly(true);
Embed images directly in HTML options.setExportImagesAsBase64(true);
Control the default font when a font is missing options.setDefaultFontName("Arial"); (or any fallback you prefer)
Debug which fonts are being used Call Workbook.getWorksheets().get(i).getCells().get(i, j).getStyle().getFont().getName(); and log the font names prior to conversion.

References


If you still see a different font after following the steps above, please let us know:

  1. Which font(s) are used in the original workbook (you can retrieve them via the API).
  2. The operating system and Java version where the conversion runs.
  3. A small sample workbook (if possible) that reproduces the issue.

We’ll be happy to dive deeper.

The problem is not that the font does not exist on the server that does the converting.
It seems there is some weird bug when a cell contains 2 different fonts.

@jtimmer,

Thanks for providing us template Excel file and screenshots.

After initial testing, I reproduced the issue as you mentioned by using your template Excel file to convert to HTML. I found font is wrong for the cells (which has two different types of font for the contents) when converting Excel file to HTML.

// Load the workbook
Workbook wb = new Workbook("Test.xlsx");

// Prepare HTML save options
HtmlSaveOptions options = new HtmlSaveOptions();
options.setExportActiveWorksheetOnly(true); 
// Save as HTML
wb.save("Test.html", options);

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSJAVA-46496

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@jtimmer ,

We are pleased to inform you that your issue has been resolved. The fix will be included in an upcoming release (Aspose.Cells v25.10) that we plan to release in the first half of October 2025. You will be notified when the next version is released.

The result after applying the fix is attached for your review:
output.zip (2.1 KB)