I am using
Aspose.Cells 25.9.0.
.NET 9.0
HTML file is displayed incorrectly with “Freeze Panes”
If I use the “Freeze Panes” feature in the table, the conversion to HTML is INCORRECT.
If I use the “Unfreeze Panes” feature in the table, the conversion to HTML is CORRECT.
“Freeze Panes” can be found it in Excel here:
Ribbon > View tab > Window group > Freeze Panes
Code:
HtmlSaveOptions options = new()
{
ExportImagesAsBase64 = true,
ExportPrintAreaOnly = true,
ExportHiddenWorksheet = false,
ExcludeUnusedStyles = true,
ExportActiveWorksheetOnly = true,
Encoding = Encoding.UTF8,
EmbeddedFontType = HtmlEmbeddedFontType.Woff
};
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 = wbc.Worksheets.Names.First(x => x.FullText == "tests_freeze_pans").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());
input.zip (9.0 KB)
output.zip (10.7 KB)
@aleksandr.l
It appears that the “Freeze Panes” feature in your Excel file is impacting the HTML conversion process. When “Freeze Panes” is applied, the layout may not render correctly in HTML format, while removing it can facilitate a proper conversion.
To troubleshoot this issue, consider the following steps:
-
Check the Range: Ensure that the range you are converting does not include any frozen panes. Adjust the range to exclude any frozen rows or columns.
-
Use Different Save Options: Experiment with various HtmlSaveOptions
settings. For example, try setting ExportActiveWorksheetOnly
to false
to see if it improves the output.
-
Manual Adjustment: If the problem persists, you may need to manually adjust the HTML output after conversion to correct any layout issues caused by frozen panes.
Here’s a modified version of your code that sets the ExportActiveWorksheetOnly
option to false
:
HtmlSaveOptions options = new()
{
ExportImagesAsBase64 = true,
ExportPrintAreaOnly = true,
ExportHiddenWorksheet = false,
ExcludeUnusedStyles = true,
ExportActiveWorksheetOnly = false, // Changed to false
Encoding = Encoding.UTF8,
EmbeddedFontType = HtmlEmbeddedFontType.Woff
};
// Your existing code...
If these suggestions do not resolve the issue, consider reaching out to the Aspose.Cells support forum for more specific guidance.
@aleksandr.l,
Thanks for the sample files and details.
We will evaluate and test your issue using your sample file and get back to you with our findings soon.
@aleksandr.l.
I tested your scenario/case using your template Excel file and sample code snippet. I found freeze pane (Excel) feature was not rendered in the output HTML file. Then, I tested your task in MS Excel manually and found the same issue. Please note, frozen panes would be lost in the output HTML when rendering from Excel file. The behavior is same with MS Excel. To confirm this, please open your Excel file into MS Excel manually. Now save it as “Web Page” with some file name, e.g., “output.html”. Close the workbook. Now open your generated HTML file into some browser and you will see similar result as generated by Aspose.Cells APIs.
Should you have further queries or comments, feel free to write us back.
@aleksandr.l
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-59126
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.
1 Like
Hi @amjad.sahi
I tested in my side
I saved input.xlsx as input.html
In input.html, layout looks correct but unfortunately it is not similar to what Aspose.Cells does in output.html
archive.zip (26.8 KB)
@aleksandr.l,
Thank you for providing the sample files.
I apologize for any inconvenience caused. Upon reviewing your issue further, I realize I misunderstood your issue. I had assumed you were looking to render frozen panes (similar to the functionality in MS Excel, where specific rows and/or columns can be locked in place to remain visible while scrolling through the rest of the spreadsheet) in the HTML output generated from an XLSX file. I overlooked the layout issue.
Now I understand that your requirement is solely to maintain the same layout when rendering your desired printable area or range to HTML format, without involving frozen panes. Currently, there is indeed a layout issue in the output HTML, and we have logged a ticket (“CELLSNET-59126”) to address this problem promptly.
By the way, if you save the Excel file to HTML without specifying the printable area or range (i.e., comment the line: worksheet.PageSetup.PrintArea = range.Address;
), the output works correctly (almost same as per your input.html file which was saved by MS Excel manually).
Once we resolve the issue (“CELLSNET-59126”) or have any updates regarding it, we will inform you here. Thank you for your patience and understanding.