Hello,
We are seeing an issue in Aspose Cells version 17.4.0 where a worksheet that has filters will unhide the hidden (filtered) rows when the sheet is copied. The primary issue is that when we convert the copied worksheet to HTML, the unhidden columns are included in the output.
In the attached workbook “FilteredRows.xlsx”:
A filter is applied in cell A1.
There’s a named range “TestData” which is the target for the HTML output.
The rows that is meant to be hidden are highlighted in red.
We can reproduce this issue under the latest Cells version 17.4.0, using this code:
public static void main(String[] args) {
try {
setLicense(); //set the license
// attached workbook
String path = “C:\Temp\FilteredRows.xlsx”;
String namedRng = “TestData”;
Workbook wb = new Workbook(path);
Name name = wb.getWorksheets().getNames().get(namedRng);
Range rng = name.getRange();
Worksheet sheet = rng.getWorksheet();
Cells cells = sheet.getCells();
int sheetIdx = sheet.getIndex();
int firstCol = rng.getFirstColumn();
int firstRow = rng.getFirstRow();
int colCnt = rng.getColumnCount();
int rowCnt = rng.getRowCount();
int maxCol = cells.getMaxDisplayRange().getColumnCount();
int maxRow = cells.getMaxDisplayRange().getRowCount();
// Create a copy of the worksheet - such that only the copy is modified
int newSheetIdx = wb.getWorksheets().addCopy(sheetIdx);
// BUG NOTE:
// The copied worksheet does NOT have the filter applied and therefore
// the filtered (hidden) rows from the original sheet are now visible
// redefine the ranges using the copied worksheet
wb.getWorksheets().setActiveSheetIndex(newSheetIdx);
sheet = wb.getWorksheets().get(newSheetIdx);
cells = sheet.getCells();
rng = cells.createRange(firstRow, firstCol, rowCnt, colCnt);
// Manually hide all the columns not part of the named range
if (firstCol > 0) {
cells.hideColumns(0, firstCol);
}
if (firstCol + colCnt < maxCol) {
cells.hideColumns(firstCol + colCnt, maxCol + 1);
}
// Manually hide all the rows not part of the range
if (firstRow > 0) {
cells.hideRows(0, firstRow);
}
if (firstRow + rowCnt < maxRow) {
cells.hideRows(firstRow + rowCnt, maxRow);
}
// Now export the copied worksheet
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.setHiddenColDisplayType(HtmlHiddenColDisplayType.REMOVE);
options.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.REMOVE);
wb.save(path.replace(".xlsx", “.html”), options);
System.out.println(“Successfully created HTML file:\n " +
path.replace(”.xlsx", “.html”));
} catch (Exception ex) {
System.out.println(“Unexpected EXCEPTION: \n\t” +
ex.getMessage());
}
}
Thanks.