HTML file is displayed incorrectly

I am using
Aspose.Cells 25.7.0.
.NET 9.0

HTML file is displayed incorrectly in MacOS

Windows Everything displays correctly in Google Chrome and Edge
Mac OS The layout displays incorrectly in Google Chrome and Safari

I compiled project in Windows and tested output file on two operating systems.

code:

static Name? GetNameByName(Workbook wb, string? namedRange)
{
    foreach (var name in wb.Worksheets.Names)
    {
        if (name.Text == namedRange || name.FullText == namedRange)
        {
            return name;
        }
    }
    
    return null;
}

HtmlSaveOptions options = new()
{
    ExportImagesAsBase64 = true,
    ExportPrintAreaOnly = true,
    ExportHiddenWorksheet = false,
    ExcludeUnusedStyles = true,
    ExportActiveWorksheetOnly = true,
    Encoding = Encoding.UTF8
};

var input = @"C:\input.xlsx";
var output = @"C:\output.html";

Workbook? wbc;
using (var ms = new FileStream(input, FileMode.Open))
    wbc = new Workbook(ms, new LoadOptions(LoadFormat.Xlsx));

wbc.CalculateFormula();

var range = GetNameByName(wbc,"DR_PUBv2__1756479770")!.GetRange()!;
var worksheet = range.Worksheet;
worksheet.PageSetup.PrintArea = range.Address;
wbc.Worksheets.ActiveSheetIndex = worksheet.Index;
using var html = new MemoryStream();
wbc.Save(html, options);
File.WriteAllBytes(output, html.ToArray());

windows: Windows.png (14.5 KB)
macos: MacOS.png (24.0 KB)
html: output.html.zip (2.5 KB)
xlsx: input.xlsx.zip (9.9 KB)

@aleksandr.l

It sounds like you’re experiencing layout issues with the HTML output generated by Aspose.Cells on macOS, while it displays correctly on Windows. This discrepancy is often related to font availability, as macOS may not have the same TrueType fonts installed that are present on Windows.

Cause: The layout issues are likely due to missing fonts on macOS, which can lead Aspose.Cells to substitute them with default fonts, resulting in differences in the rendered output.

Solution: Here are some steps you can take to troubleshoot and potentially resolve the issue:

  1. Check Font Availability: Ensure that the fonts used in your Excel file are available on the macOS system. If the fonts are missing, Aspose.Cells may substitute them with default fonts, leading to layout differences.

  2. Specify Font Directory: You can specify a directory containing the required TrueType fonts using the FontConfigs.setFontFolder method. This can help Aspose.Cells locate the necessary fonts when rendering the HTML.

  3. Adjust HTML Save Options: Experiment with different settings in the HtmlSaveOptions. For instance, enabling AutoFitColsAndRows can help adjust the layout dynamically based on the content.

Here’s a modified version of your code snippet that includes setting the font directory:

// Set the font directory
FontConfigs.SetFontFolder("path_to_your_fonts", true);

HtmlSaveOptions options = new HtmlSaveOptions
{
    ExportImagesAsBase64 = true,
    ExportPrintAreaOnly = true,
    ExportHiddenWorksheet = false,
    ExcludeUnusedStyles = true,
    ExportActiveWorksheetOnly = true,
    Encoding = Encoding.UTF8,
    AutoFitColsAndRows = true // Enable auto-fit
};

// Your existing code...
  1. Test with Different Browsers: Since you mentioned that the issue occurs in both Chrome and Safari on macOS, it might be worth testing the output in other browsers or checking for any browser-specific rendering issues.

Next Steps: Please try the above steps and let me know if they help resolve the issue. If the problem persists, provide any additional details about the fonts used or the specific layout discrepancies you are encountering, and I will assist you further. Thank you!

I am already using this code: FontConfigs.SetFontFolder(dir, true);

@aleksandr.l,

Thank you for sharing the sample files and screenshots.

It appears that the issue might be related to missing fonts on macOS. This could be due to differences in font availability, as macOS may not include certain TrueType fonts (e.g., Calibri, Verdana) that are available on Windows, where the HTML displays correctly.

Could you kindly check and confirm if the fonts used in your Excel file are installed on the macOS system?

If you believe that the required fonts are already installed, may I request you to save the document as a PDF file (including the necessary lines of code) and then process the updated code on macOS to generate the PDF? Please share the resulting PDF file with us, and we will review it soon.

Hi,

Thank you

~ % fc-list | grep -i “calibri”
fc-list | grep -i “verdana”

/System/Library/Fonts/Supplemental/Verdana Bold.ttf: Verdana:style=Bold,Negreta,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,Lodia
/System/Library/Fonts/Supplemental/Verdana Italic.ttf: Verdana:style=Italic,Cursiva,kurzíva,kursiv,Πλάγια,Kursivoitu,Italique,Dőlt,Corsivo,Cursief,Kursywa,Itálico,Курсив,İtalik,Poševno,Etzana
/System/Library/Fonts/Supplemental/Verdana.ttf: Verdana:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
/System/Library/Fonts/Supplemental/Verdana Bold Italic.ttf: Verdana:style=Bold Italic,Negreta cursiva,tučné kurzíva,fed kursiv,Fett Kursiv,Έντονα Πλάγια,Negrita Cursiva,Lihavoitu Kursivoi,Gras Italique,Félkövér dőlt,Grassetto Corsivo,Vet Cursief,Halvfet Kursiv,Pogrubiona kursywa,Negrito Itálico,Полужирный Курсив,Tučná kurzíva,Fet Kursiv,Kalın İtalik,Krepko poševno,Lodi etzana

I checked, looks like Verdana is there

@aleksandr.l,

It seems like “Calibri” font is missing on your end. Please install the font and then test your scenario/case.

Unfortunately, we cannot do that.

Users do not use Aspose application locally. They use resulting HTML on website. Perhaps the issue is not withfonts, as font is the same (Verdana) and it is installed on Mac.

Are there other options for getting the same HTML on Mac and Windows?

@amjad.sahi
When installing Calibri, everything works, but we use many fonts in build FontConfigs.SetFontFolder(dir, true);

Are there any functions that allow us to use cross-platform fonts?

We do not have access to the user’s pc. The user opens HTML pages on website.

@aleksandr.l,

I am afraid, to view the output HTML precisely, you must have required fonts installed on the user machine(s). Generally Aspose.Cells works the same way as MS Excel when rendering spreadsheets to HTML. Even you could try to save the Excel file to HTML (Web Page) manually in MS Excel on Windows, then open the HTML file on macOS machine (where calibri font is not installed)to check if you could see correct display of HTML file?

I saved the xlsx file as htm and html
and opened it on Windows, and it works correctly.
I opened it on Mac and it does not work correctly.

What can we offer our users besides installing Calibri font?
Is there way to replace it with cross-platform font or is there API or other options?

@aleksandr.l ,

The issue may be resolved by embedding fonts in the output file.
Currently, Aspose.Cells supports embedding fonts while converting to svg.

SvgImageOptions svgImageOptions = new SvgImageOptions();
svgImageOptions.EmbeddedFontType = SvgEmbeddedFontType.Woff;
svgImageOptions.OnePagePerSheet = true;

Workbook wbc = new Workbook("input.xlsx");

wbc.CalculateFormula();

var range = wbc.Worksheets.GetRangeByName("DR_PUBv2__1756479770");
var worksheet = range.Worksheet;
worksheet.PageSetup.PrintArea = range.Address;

SheetRender sheetRender = new SheetRender(worksheet, svgImageOptions);
sheetRender.ToImage(0, "output.svg");

Please check the attached svg file on your Mac OS. If it works OK and you need the feature that embedding font while converting to html, we will evaluate it.
output_svg.zip (22.6 KB)

1 Like

Hi @peyton.xu,
Thank you, it works on Mac OS without Calibri fonts.
Please tell me, have I understood correctly that you will be developing this feature?

image.png (26.1 KB)

@aleksandr.l
Your understanding is correct. We will support embedding fonts when converting file to html.

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): CELLSNET-58961

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.

@aleksandr.l
As a temporary alternative, you can use fonts that can be displayed to replace fonts that are not installed. Please refer to the following example code.

Workbook wb = new Workbook(filePath + "sample.xlsx");
for (int i = wb.CountOfStylesInPool - 1; i > -1; i--)
{
    Style s = wb.GetStyleInPool(i);
    Aspose.Cells.Font f = s.Font;
    if (f.Name == "Calibri")
    {
        //Set alternative fonts that can be displayed
        f.Name = "Arial";
    }
}
Style df = wb.DefaultStyle;
if (df.Font.Name == "Calibri")
{
    //Set alternative fonts that can be displayed
    df.Font.Name = "Arial";
}
wb.DefaultStyle = df;
wb.Save(filePath + "out_net.xlsx");

Hope helps a bit.

@aleksandr.l ,

Please check the attached HTML file with the embedding fonts on your Mac OS( where Calibri is not installed) and let us know if it displays correctly. This will help us confirm whether the embedding font is working as expected.
EmbeddedFont.zip (22.4 KB)

Hi,

@Eric.wang
It works perfectly on Windows and Mac OS

@aleksandr.l,

Thank you for your feedback. We are glad that the provided HTML with embedded fonts meets your requirements on Mac OS. We are optimistic that the enhancement (support for embedding fonts when converting Excel files to HTML) will be included in our upcoming release, Aspose.Cells v25.9, which is planned in the next week of September 2025. Rest assured, we will notify you promptly once the supported version becomes available.

1 Like

@aleksandr.l ,

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