We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Merged Cells Included in Hidden Rows or Columnns Produce an Uneven HTML Table

Hello,

A Range containing merged cells that are part of hidden rows or columns generates an HTML table where some cells are offest from their intended location. In other words, some cells appear in rows or columns that should not be part of the table.

This behavior can be seen in the latest Aspose Cells for Java version 21.6, the attached MergedCellsHiddenRowsCols.xlsx file and the following Java code:

final String xlFile = [PATH] + "MergedCellsHiddenRowsCols.xlsx";
final String newName = "-%s-v" + CellsHelper.getVersion() + ".html";

for (String name :  Arrays.asList("export_hidden_cols", "export_hidden_rows")) {
  final Workbook wb = new Workbook(xlFile);
  
  final Name xlName = wb.getWorksheets().getNames().get(name);
  final Range rng = xlName.getRange();
  
  CellArea area = CellArea.createCellArea(rng.getFirstRow(), rng.getFirstColumn(),
                                          rng.getFirstRow() + rng.getRowCount() - 1 ,
                                          rng.getFirstColumn() + rng.getColumnCount() - 1);
  
  wb.getWorksheets().setActiveSheetIndex(xlName.getRange().getWorksheet().getIndex());
  
  final HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
  options.setEncoding(Encoding.getUTF8());
  options.setHtmlCrossStringType(HtmlCrossType.CROSS);
  options.setPresentationPreference(true);
  options.setExportHiddenWorksheet(false);
  options.setExportActiveWorksheetOnly(true);
  options.setExportImagesAsBase64(true);
  options.setCreateDirectory(false);
  options.setExpImageToTempDir(false);
  options.setExcludeUnusedStyles(true);
  options.setExportComments(false);
  options.setExportDocumentProperties(false);
  options.setExportWorksheetProperties(false);
  options.setExportBogusRowData(false);
  options.setExportFrameScriptsAndProperties(false);
  options.setValidateMergedAreas(true);
  
  // NOTE: We are removing hidden ROWS/COLS
  options.setHiddenColDisplayType(HtmlHiddenColDisplayType.REMOVE);
  options.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.REMOVE);
  
  options.setExportArea(area);
  
  String htmlFile = xlFile.replace(".xlsx", String.format(newName, name));
  Files.deleteIfExists(Paths.get(htmlFile));
  wb.save(htmlFile, options);
  System.out.println("Successfully created HTML file:  " + htmlFile);
}

Key Observations:

  1. The export ranges in the Workbook have merged cells where the merge area spans into hidden rows or columns.
  2. Running the above code under Cells 21.6, should produce a file similar to the attached MergedCellsHiddenRowsCols-export_hidden_cols-v21.6.0.html and `MergedCellsHiddenRowsCols-export_hidden_rows-v21.6.0.html1 files.
  3. If you render the HTML files in a Browser you should see that the HTML tables are uneven and the some cells appear in unexpected coordinates.
  4. This issue seems to be regressive. If you run the same code as above using Aspose Cells for Java version 19.11, the resulting tables appear as expected. See files MergedCellsHiddenRowsCols-export_hidden_cols-v19.11.0.html and MergedCellsHiddenRowsCols-export_hidden_rows-v19.11.0.html.

Environment Details:

  • Aspose Cells for Java 21.6
  • Java version 1.8.0_211
  • Windows 10 OS (but also reproducible under Linux).

File description in the MergedCellsHiddenRowsCols.zip (22.0 KB) attachment:

  • MergedCellsHiddenRowsCols.xlsx: Workbook to be used by the code above.
  • MergedCellsHiddenRowsCols-export_hidden_cols-v21.6.0.html: First HTML file generated after running the code above under Cells version 21.6 on our environment.
  • MergedCellsHiddenRowsCols-export_hidden_rows-v21.6.0.html: Second HTML file generated after running the code above under Cells version 21.6 on our environment.
  • MergedCellsHiddenRowsCols-export_hidden_cols-v19.11.0.html: First HTML file generated after running the code above under Cells version 19.11 on our environment.
  • MergedCellsHiddenRowsCols-export_hidden_rows-v19.11.0.html: Second HTML file generated after running the code above under Cells version 19.11 on our environment.

Thank you!

@oraspose,

Please notice, I am able to reproduce the issue as you mentioned (as per your observations and findings) by using your template file and code. I found merged cells included in hidden rows and columns produce uneven HTML tables. I have logged a ticket with an id “CELLSJAVA-43519” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.