Save to HTML: irrelevant data included

@TarasTielkes,
Because a style may be referenced by cells in multiple worksheets, if forced collection, there will be style problems in cells in other worksheets. Therefore, only by deleting other worksheets and collecting styles can we ensure that the styles are correct.

Hi @John.He,

If I use LightCellsDataHandler to only load an individual sheet from the workbook, that should have the same effect, is that correct?

Kind regards,
Taras

@TarasTielkes,
Yes, you are correct.

The issues you have found earlier (filed as CELLSJAVA-42494) have been fixed in this update.

Hi @johnson.shi,

Using Aspose Cells for Java, version 21.9, the output is better, but there are still unused styles included in the HTML output.

Sample code:

LoadOptions loadOptions = new LoadOptions();
loadOptions.setLoadFilter(new SpecificSheetAndOptionsLoadFilter("Entry points", LoadDataFilterOptions.ALL));
Workbook workbook = new Workbook("input.xlsx", loadOptions);
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet worksheet = worksheets.get("Entry points");
int index = worksheet.getIndex();

worksheets.setActiveSheetIndex(index);

HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.HTML);
saveOptions.setParseHtmlTagInCell(false);
saveOptions.setExportHiddenWorksheet(false);
saveOptions.setExportActiveWorksheetOnly(true);

saveOptions.setExportDocumentProperties(false);
saveOptions.setExportWorkbookProperties(false);
saveOptions.setExportWorksheetProperties(false);
saveOptions.setExportFrameScriptsAndProperties(false);
saveOptions.setExportBogusRowData(false);
saveOptions.setExportComments(false);
saveOptions.setEncoding(Encoding.getUTF8());

saveOptions.setExcludeUnusedStyles(true);

workbook.save("output.html", saveOptions);

In the generated result, the following styles are included in the CSS, but are unused in the HTML:

  • .style0
  • .x15

Input for sample code, and output from Aspose Cells for Java, version 21.9:
21.9.zip (1.4 MB)

That said, it is a good improvement over the HTML/CSS output of previous Aspose Cells versions.

Kind regards,
Taras

@TarasTielkes,
Thank you for the feedback. We have noted your concern about the minor issue of remaining unused styles. We will look into it and share our findings soon.

@TarasTielkes,

The style .style0, .x15 is the default style of the workbook. And, the default style is needed for workbook. You can try to reload the generated HTML file and output the default style with the following code:

Workbook workbook = new Workbook("output.html");
System.out.println(workbook.getDefaultStyle().getFont());

Then, you can manually delete style .style0, .x15 in the generated output HTML. Then try to reload the modified output.html with the above code, you will see the difference.