Hello team.
While evaluating latest Aspose.Cells library, we noticed sometimes HtmlSaveOptions.setExcludeUnusedStyles() is ignored when Workbook is saved as HTML.
To reproduce this issue, you can use attached workbook and the following code sample:
static final String PATH = <PATH_TO_INPUT_WORKBOOK>;
Workbook wb = new Workbook(PATH + “ConditionalFormats.xlsx”);
try {
// Specify the HTML Saving Options
options.setEncoding(Encoding.getUTF8());
// Note use HtmlCrossType.CROSS since DEFAULT can produce unwanted results in
// some scenarios
options.setHtmlCrossStringType(HtmlCrossType.CROSS);
options.setPresentationPreference(true);
options.setExportHiddenWorksheet(false);
options.setExportActiveWorksheetOnly(true);
options.setExportImagesAsBase64(true);
options.setCreateDirectory(false);
options.setExpImageToTempDir(false);
options.setHiddenColDisplayType(HtmlHiddenColDisplayType.REMOVE);
options.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.REMOVE);
// The following options reduce the size of the generated HTML (without
// impacting quality)
options.setExportFormula(false);
**options.setExcludeUnusedStyles(true);**
options.setExportComments(false);
options.setExportDocumentProperties(false);
options.setExportWorksheetProperties(false);
options.setExportBogusRowData(false);
options.setExportFrameScriptsAndProperties(false);
wb.save(htmlFile, options);
System.out.println("Successfully created HTML file: " + htmlFile);
} catch (IOException e) {
// Print and display the exceptions
System.out.println(e);
}
The generated html contains style .x25 which is not used in the HTML.
Please let us know if you have any questions.
Thank you.
@oraspose
It seems you are experiencing an issue where the HtmlSaveOptions.setExcludeUnusedStyles()
method is not functioning as expected when saving a workbook as HTML. This can lead to the inclusion of unused styles in the generated HTML, which is not desirable.
To address this, it’s important to ensure that the excludeUnusedStyles
property is correctly set to true
in your HtmlSaveOptions
. This property is designed to exclude any styles that are not used in the workbook from the output HTML, thereby reducing the size of the generated file.
Here’s a brief overview of how to use this property effectively:
-
Set the Property: Make sure you are setting options.setExcludeUnusedStyles(true);
before calling the wb.save(htmlFile, options);
method.
-
Check for Other Settings: Sometimes, other settings in HtmlSaveOptions
might interfere with the exclusion of unused styles. Review your options to ensure there are no conflicting settings.
-
Test with Different Workbooks: If possible, test the same code with different Excel workbooks to see if the issue persists across all files or is specific to the one you are using.
-
Update Aspose.Cells: Ensure you are using the latest version of the Aspose.Cells library, as bugs and issues are often resolved in newer releases.
Here is a simplified version of your code that highlights the relevant part:
Workbook wb = new Workbook(PATH + "ConditionalFormats.xlsx");
HtmlSaveOptions options = new HtmlSaveOptions();
options.setExcludeUnusedStyles(true); // Ensure this is set to true
// Other options...
wb.save(htmlFile, options);
If the problem continues after these checks, it may be beneficial to reach out to Aspose support with the specific workbook you are using, as they can provide more targeted assistance.
For further details on excluding unused styles during Excel to HTML conversion, you can refer to the official documentation which outlines the usage of the HtmlSaveOptions.exclude_unused_styles
property here and here.
If you have any more questions or need further assistance, feel free to ask!
Attached archive contains the input worksheet and output HTML containing unused style:
ConditionalFormats.7z (10.5 KB)
Thank you.
@oraspose,
Thanks for the template Excel file.
After initial testing, I am able to reproduce the issue as you mentioned by using your template Excel file and sample code segment. I found an extra unused style (“.x25”) was created when workbook is saved as HTML.
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-46190
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.
@oraspose ,
The style .x25
is the original style of cell "B5"
.Normally its output <td>
would contain class='x25'
, However, since"B5"
has Conditional Formatting applied, this causes the original style to be overwritten, and thus we do not write class='.x25'
to <td>
. Instead, the corresponding <td>
of the child <table>
has class='x28'
,see the following HTML snippet. . Although we do not explicitly write class='.x25'
for the <td>
, we think it is still unnecessary to remove the style .x25
.
<td height='17' width='75' style='text-align: left;height:12.75pt;width:56.25pt;font-size:11pt;color:#000000;font-weight:400;text-decoration:none;text-line-through:none;font-family:Calibri,sans-serif;background:none;mso-pattern:auto;border-top:1px solid windowtext;border-right:1px solid windowtext;border-bottom:1px solid windowtext;border-left:1px solid windowtext;vertical-align:top;' align='left'>
<span style='mso-ignore:vglayout;position:absolute;z-index:0;margin-left:37px;margin-top:0px;width:36px;height:15px'><img width='36' height='15' src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAPCAYAAACMa21tAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAALklEQVR4XmNgGGwg+XDL/8GERx1ECI86iBAedRAhPOogQnjUQYTwqIMI4UHnIABuyD0EtBVxlQAAAABJRU5ErkJggg=="/></span><span style='mso-ignore:vglayout2'>
<table cellpadding='0' cellspacing='0'> <tr>
<td height='17' class='x28' width='75' style='visibility:hidden;position:relative;background:transparent;height:12.75pt;width:56.25pt;'>1</td>
</tr></table></span>
</td>