Export specific range in Excel to HTML conversion with Aspose.Cells for Java API

Hi,

In Excel, when saving as HTML, I can specify a specific range to include.
It would be useful to have the same feature in Aspose Cells.

Kind regards,
Taras

@TarasTielkes,

Thanks for your query.

Yes, the feature is supported, you can render specific range to HTML. See the document for your reference:

Hope, this helps a bit.

@Amjad_Sahi,

Thank you, that’s exactly what I was looking for.

Kind regards,
Taras

@ TarasTielkes,

Good to know that it suits your needs well. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Hi @Amjad_Sahi

While the suggestion works, it has an undesired side-effect: as expected, it actually modifies the print area for the worksheet(s) in question.

In out scenario, we save a number of parts from various sheets to HTML, perform a bit of processing, then store the file in our system. Using the approach you suggests will show the print areas in Excel when the file is opened again.

In order to work around this, we would have to, for each HTML export that we perform:

  • check if the sheet defines a print selection, and if so, store it
  • set out custom print selection to limit the content range we want to save to HTML
  • afterwards, restore the previously defined print area (if any), since we want to leave the workbook in a state close to the original

This is an API design problem at the side of Aspose Cells: in order to adjust the range of data that I am exporting to HTML, I should not need to midify/mutate the underlying workbook. Instead of conflating different usages into single setPrintArea method, the area to export should simply be specified in the SaveOptions. That way the distinction is clear:

  • to modify the actual print area configured for the worksheet, use the method you suggested
  • to restrict the HTML (or PDF) export to a specific range, use parameters specific to the save/export process

Note that a similar problem is present for the setActiveWorkbookOnly() save option. This requires me to modify/mutate the active sheet state of the workbook, only to allow me to export a specific sheet. Similar to the issue above, this should be cleanly separated out into SaveOptions, so that I can configure the export/save process without making changes to the actual workbook being exported.

Kind regards,
Taras

@TarasTielkes,

I am not entirely certain if this is an issue with Aspose.Cells APIs (by design). Also, how could you export specific print areas only to be exported in HTML via MS Excel, I do not see this feature is present in MS Excel. Please provide sample files and demo code to show the issue(s). We will check it soon. Aspose.Cells should follow MS Excel standards and specifications when parsing or rendering HTML files.

Hi @Amjad_Sahi,

The Excel specifications from Microsoft relate to the file format only. The specific user-accessible features change by Excel version, and when using Office 365, sometimes on a weekly basis.

While Aspose Cells should be able to read and write workbook files compatible with Excel, this does not mean that Aspose Cells should be restricted to the functionality provided by Excel. And indeed many features offered by Aspose Cells are not present in Excel as such.

The problem with HtmlSaveOptions#setExportActiveWorksheetOnly() is that it requires me to modify the workbook by changing which sheet is “current”. The problem with HtmlSaveOptions#setExportPrintAreaOnly() is that is requires me to change the given print area for a given worksheet. If I export HTML from different sheets in the workbook, and persist the workbook (in XLSX format) afterwards, as a side-effect of exporting HTML, I now end up with undesired changes in the workbook, unless I take additional effort to back-up and restore the active workbook and per-sheet print areas.

Things would be much simpler if I could simply tell the HtmlSaveOptions which sheet, and which print area(s) I want to export to HTML. That way, there is no need to modify the state of the backing workbook during the HTML export process. Just because the user interface of Excel does things a certain way does not mean that Aspose Cells should limit itself to the same flow of interaction.

That said, regarding your question, Excel does in fact allow me to pick a custom range to export to HTML - see attached screenshot.

I hope my issue is clear: it would be nice to export parts of a workbook without implicitly changing some state of the same workbook.

Kind regards,
Taras

export.png (8.2 KB)

@TarasTielkes,
We have understood your requirement but we need to look into it more. We have logged the requirement in our database for investigation and for a fix(if possible). Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSJAVA-43018 – Export print area range to HTML without implicitly changing some state of the same workbook

@TarasTielkes,
This is to inform you that we have fixed your issue (logged earlier as “CELLSJAVA-43018”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

@TarasTielkes,

Please try latest version/fix: Aspose.Cells for Java v19.10.1 (attached)

Your issue should be resolved in it. We add HtmlSaveOptions.ExportArea property which gets or sets the exporting CellArea of current active worksheet. If you set this attribute, the print area of current active worksheet will be omitted. Only the specified area will be exported when saving the file to html.

The sample codes as follows:
e.g
Sample code:

[.NET]:

  HtmlSaveOptions options = new HtmlSaveOptions();
    options.ExportPrintAreaOnly = true;
    options.ExportArea = CellArea.CreateCellArea("B5", "E7");
    Workbook wb = new Workbook(filePath + "a.xlsx");
    wb.Save(filePath + "out.html", options);

[JAVA]:

HtmlSaveOptions options = new HtmlSaveOptions();
options.setExportPrintAreaOnly(true);
options.setExportArea(CellArea.createCellArea("B5", "E7"));
Workbook wb = new Workbook(filePath + "a.xlsx");
wb.save(filePath + "out_java.html", options);

Let us know your feedback.
Aspose_Cells_Java_v19.10.1.zip (6.6 MB)

The issues you have found earlier (filed as CELLSJAVA-43018) have been fixed in Aspose.Cells for Java v19.11. This message was posted using Bugs notification tool by ahsaniqbalsidiqui