Aspose.Cells - Incorrect html is saved

I need to save certain range of cells as html.

I use Workbook.Save xlsx file as html: workbook.Save(fs, htmlOptions);
Save as HTML method does not work.

25.3.0 - Works correctly
25.4.0 - Does not work

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

var workbook = new Workbook(input);
var name = workbook.Worksheets.Names["DR_PUBv2__1678823491"];
var range = name.GetRange();

var worksheet = workbook.Worksheets.First();
worksheet.PageSetup.PrintArea = range.Address;
workbook.Worksheets.ActiveSheetIndex = worksheet.Index;
            
for (var rowOffset = 0; rowOffset < range.RowCount; rowOffset++)
{
    for (var colOffset = 0; colOffset < range.ColumnCount; colOffset++)
    {
        var cell = range[rowOffset, colOffset];
                    
        if (!cell.IsFormula)
            continue;
                    
        var styleSet = $"javascript:void(0);_DRXX$33_{cell.Name}"; <-- 
        var style = cell.GetStyle();
        workbook.Worksheets[0].Hyperlinks.Add(cell.Name, 1, 1, styleSet);
        cell.SetStyle(style);
    }
}
        
using var fs = new FileStream(output, FileMode.Create);
var htmlOptions = new HtmlSaveOptions
{
    ExportImagesAsBase64 = true,
    ExportPrintAreaOnly = true,
    ExportHiddenWorksheet = false,
    ExcludeUnusedStyles = true,
    ExportActiveWorksheetOnly = true,
    Encoding = Encoding.UTF8
};
workbook.Save(fs, htmlOptions);

input.zip (14.1 KB)
htmls.zip (5.7 KB)

@aleksandr.l

It seems you are experiencing issues with saving a specific range of cells as HTML using Aspose.Cells, particularly after upgrading from version 25.3.0 to 25.4.0. Here are some steps and considerations that might help you resolve the problem:

  1. Check Print Area: Ensure that the print area is correctly set to the desired range. In your code, you are using range.Address to set the print area. Verify that this address is correct and corresponds to the range you want to export.

  2. HtmlSaveOptions Configuration: You are already using HtmlSaveOptions to configure the export settings. Make sure that the options you are using are appropriate for your needs. For example, you have set ExportPrintAreaOnly to true, which is correct if you only want to export the defined print area.

  3. Hyperlink Handling: You are adding hyperlinks to cells based on their names. Ensure that the hyperlink format is valid and does not interfere with the HTML export. If the hyperlinks are causing issues, try commenting out that section of the code temporarily to see if it resolves the problem.

  4. Testing with Sample Code: You can refer to sample code that demonstrates exporting a print area to HTML. For instance, the following code snippet shows how to set the print area and save it as HTML:

    Workbook workbook = new Workbook("input.xlsx");
    Worksheet worksheet = workbook.Worksheets[0];
    worksheet.PageSetup.PrintArea = "D2:M20"; // Set your desired print area
    
    HtmlSaveOptions options = new HtmlSaveOptions
    {
        ExportPrintAreaOnly = true,
        ExportImagesAsBase64 = true,
        ExcludeUnusedStyles = true
    };
    
    workbook.Save("output.html", options);
    
  5. Version Compatibility: Since you mentioned that the functionality worked in version 25.3.0 but not in 25.4.0, consider checking the release notes or documentation for version 25.4.0 to see if there are any breaking changes or known issues related to HTML export.

If the problem persists, you may want to reach out to Aspose support or check the community forums for similar issues reported by other users.

Feel free to share any specific error messages or behaviors you are encountering, as that information can help in diagnosing the issue further.

Sources:
[1]: ExportPrintAreaToHtml.cs
[2]: ExportDocumentWorkbookAndWorksheetPropertiesInHTML.cs

@aleksandr.l,

Thanks for the sample files and details.

After initial testing, I am able to reproduce the issue as you mentioned by using your template Excel file and sample code snippet. I found incorrect HTML produced by newer Aspose.Cells version.

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-58268

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 ,

We are pleased to inform you that your issue has been resolved. The fix will be included in an upcoming release (Aspose.Cells v25.5) that we plan to release in the first half of May 2025. You will be notified when the next version is released.
Here is the result after fix for your reference: output.zip (3.1 KB)