Search code examples
apache-poijasper-reportsexport-to-excel

XSSFWorkbook.setActiveSheet() equivalent in JasperReports?


We're using JasperReports 6.13.0 to generate XLSX format reports. We have a requirement where we need to show a particular sheet as default visible(instead of the first sheet) whenever the user opens the generated XLSX report.

My question is, do we have this feature in JasperReports? I couldn't find anything related to it in the documentation.

Note: In Apache POI, we can achieve this functionality using: XSSFWorkbook.setActiveSheet(int index)


Solution

  • JasperReports doesn't currently include this feature.

    You can consider patching the JasperReports code to add it. What you would need to do is to add something like the following line in XlsxWorkbookHelper.exportHeader after the line with workbookPr.

        write("<bookViews><workbookView activeTab=\"" + activeSheet + "\"/></bookViews>\\n");
    

    You'd also need to pass the active sheet index somehow from the exporter.

    Alternatively, you can export to XLSX using JasperReports and then open the file with POI and set the active sheet.