Cell colors in HTML are displayed incorrectly

I am using
Aspose.Cells 25.7.0.
.NET 9.0

The cells are colored differently via Home > Styles > Conditional Formatting and Style is applied to the cells via Format Cells > Fill > Pattern Style.

Everything is fine in Excel, but the colors are incorrect in HTML

If Pattern Style is removed, everything works correctly.

code:

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

var input = @"C:\input-for-aspose.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 = wbc.Worksheets.Names.First(x => x.FullText == "test_cells_colors").GetRange()!;
var worksheet = range.Worksheet;
worksheet.PageSetup.PrintArea = range.Address;
wbc.Worksheets.ActiveSheetIndex = worksheet.Index;
using var html = new MemoryStream();
wbc.Save(html, options);
var arr = html.ToArray();
File.WriteAllBytes(output, html.ToArray());

xlsx: input-for-aspose.zip (8.5 KB)
html: output.zip (18.3 KB)

@aleksandr.l

The issue with cell colors in the HTML output is likely due to the use of Pattern Style in your Excel file. Aspose.Cells may not fully support all Excel formatting features when exporting to HTML, especially complex styles like conditional formatting combined with pattern styles.

To work around this issue, consider the following options:

  1. Remove Pattern Style: As you’ve noted, removing the pattern style resolves the color display issue. If possible, adjust your Excel file to avoid using pattern styles.

  2. Use a Different Export Format: If maintaining the visual fidelity of your Excel file is essential, consider exporting to a format that better supports the styles, such as PDF.

  3. Custom HTML/CSS Styling: If you need to keep the HTML output, you can manually apply CSS styles to the generated HTML to match the intended colors.

Here’s a minimal example of how to adjust your code to export to PDF instead:

var pdfOutput = @"C:\output.pdf";
wbc.Save(pdfOutput, SaveFormat.Pdf);

This approach ensures that the colors and styles are preserved as they appear in Excel.

If you have further questions or need additional assistance, feel free to ask!

@aleksandr.l,

Thanks for the template Excel file, output HTML and sample code snippet.

After initial testing, I am able to reproduce the issue as you mentioned by using your template Excel file. I found cell colors (formatting) in HTML are displayed incorrectly which are not matched with the source cells in XLSX file.

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

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.