Hello,
We found a bug that seems to be regressive to Aspose Cells version 8.6.3. Under Aspose Cells version 8.6.2, it was possible to hide columns prior to converting a worksheet to HTML. However, as of version 8.6.3, the hidden columns cause the resulting HTML to produce an empty table.
To reproduce this issue:
First extract the “HiddenCols.xlsx” file attached and create a Java class with the following test code:
try {
setLicense(); // internal method to set the License<span style="color: #000080">String </span><span style="color: #000000">wbPath = </span><span style="color: #555555">"HiddenCols.xlsx"</span><span style="color: #000000">;</span> </span><span style="font-family: Consolas"><span style="font-family: Consolas"><span style="color: #008000">// assumes file is in path</span></span> <span style="color: #000000">Workbook wb = </span><span style="color: #0000ff">new </span><span style="color: #000000">Workbook(</span></span><span style="font-family: Consolas"><span style="color: #000000"><span style="font-family: Consolas"><span style="color: #000080"></span><span style="color: #000000">wbPath</span></span>);</span> <span style="color: #000000">NameCollection names = wb.getWorksheets().getNames();</span> <span style="color: #000080">Name </span><span style="color: #000000">name = names.get(</span><span style="color: #555555">"<b>PartialHidden</b>"</span><span style="color: #000000">);</span> <span style="color: #000000">Range rng = name.getRange();</span> <span style="color: #000000">Worksheet sheet = rng.getWorksheet();</span> <span style="color: #000000">Cells cells = sheet.getCells();</span> <span style="color: #0000ff">int </span><span style="color: #000000">firstCol = rng.getFirstColumn();</span> <span style="color: #0000ff">int </span><span style="color: #000000">firstRow = rng.getFirstRow();</span> <span style="color: #0000ff">int </span><span style="color: #000000">maxCol = cells.getMaxDisplayRange().getColumnCount();</span> <span style="color: #0000ff">int </span><span style="color: #000000">maxRow = cells.getMaxDisplayRange().getRowCount();</span> <span style="color: #008000">// HIDE all the rows and columns that are not part of the range (zero-based)</span> <span style="color: #0000ff">if </span><span style="color: #000000">(firstCol > </span><span style="color: #ff0000">0</span><span style="color: #000000">) {</span> <span style="color: #000000">cells.hideColumns(</span><span style="color: #ff0000">0</span><span style="color: #000000">, firstCol);</span> <span style="color: #000000">}</span> <span style="color: #0000ff">if </span><span style="color: #000000">(firstCol + rng.getColumnCount() < maxCol) {</span> <span style="color: #000000">cells.hideColumns(firstCol + rng.getColumnCount(), maxCol);</span> <span style="color: #000000">}</span> <span style="color: #0000ff">if </span><span style="color: #000000">(firstRow > </span><span style="color: #ff0000">0</span><span style="color: #000000">) {</span> <span style="color: #000000">cells.hideRows(</span><span style="color: #ff0000">0</span><span style="color: #000000">, firstRow);</span> <span style="color: #000000">}</span> <span style="color: #0000ff">if </span><span style="color: #000000">(firstRow + rng.getRowCount() < maxRow) {</span> <span style="color: #000000">cells.hideRows(firstRow + rng.getRowCount(), maxRow);</span> <span style="color: #000000">}</span> <span style="color: #000000">wb.getWorksheets().setActiveSheetIndex(sheet.getIndex());</span> <span style="color: #008000">// export the worksheet</span> <span style="color: #000000">HtmlSaveOptions options = </span><span style="color: #0000ff">new </span><span style="color: #000000">HtmlSaveOptions(SaveFormat.</span><span style="color: #000080">HTML</span><span style="color: #000000">);</span> <span style="color: #000000">options.setEncoding(</span><span style="color: #000080">Encoding</span><span style="color: #000000">.getUTF8());</span> <span style="color: #000000">options.setHtmlCrossStringType(HtmlCrossType.CROSS);</span> <span style="color: #000000">options.setPresentationPreference(</span><span style="color: #0000ff">true</span><span style="color: #000000">);</span> <span style="color: #000000">options.setExportActiveWorksheetOnly(</span><span style="color: #0000ff">true</span><span style="color: #000000">);</span> <span style="color: #000000">options.setExportImagesAsBase64(</span><span style="color: #0000ff">true</span><span style="color: #000000">);</span> <span style="color: #000000">options.setCreateDirectory(</span><span style="color: #0000ff">false</span><span style="color: #000000">);</span> <span style="color: #000000">options.setExpImageToTempDir(</span><span style="color: #0000ff">false</span><span style="color: #000000">);</span> <span style="color: #008000">// Note, HtmlHiddenColDisplayType.REMOVE is used for columns only. <br></span></span><span style="font-family: Consolas"><span style="color: #008000"><span style="font-family: Consolas"> <span style="color: #008000">// </span></span>We found a different bug where</span> </span><span style="font-family: Consolas"><span style="font-family: Consolas"><span style="color: #008000">the hidden columns were showing up</span></span> <span style="color: #008000">// </span></span><span style="font-family: Consolas"><span style="color: #008000"><span style="font-family: Consolas"><span style="font-family: Consolas"><span style="color: #008000">in the transformed HTML - </span></span></span>even though they are hidden.</span> <span style="color: #000000">options.setHiddenColDisplayType(HtmlHiddenColDisplayType.REMOVE);</span> <span style="color: #000080">String </span><span style="color: #000000">html = </span></span><span style="font-family: Consolas"><span style="color: #000000"><span style="font-family: Consolas"><span style="color: #000080"></span><span style="color: #000000">wbPath</span></span>.replace(</span><span style="color: #555555">".xlsx"</span><span style="color: #000000">, <font color="#0000FF">CellsHelper.getVersion()</font> + </span><span style="color: #555555">".html"</span><span style="color: #000000">);</span> <span style="color: #000000">wb.save(html, options);</span>
} catch (Exception ex) {
System.out.println(“Unexpected EXCEPTION: \n\t” + ex.getMessage());
ex.printStackTrace();
}
Next steps:
- Run the program using Aspose Cells 8.7.0 or 8.6.3
- Open the resulting HTML file. Notice it has an empty table. None of the expected data from the exported worksheet exists in the produced HTML.
- Now run the program using Aspose Cells 8.6.2.
- Notice the resulting HTML contains the expected worksheet data.
- Windows 7 running Java 1.7.0_85 and
- LINUX 5 running Java 1.7.0_85.