public void xlsx() throws JRException {
    long start = System.currentTimeMillis();
    File sourceFile = new File("build/reports/JRMDbReport.jrprint");

    JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(sourceFile);

    File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xlsx");

    JRXlsxExporter exporter = new JRXlsxExporter();

    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));
    SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration();
    configuration.setOnePagePerSheet(false);
    exporter.setConfiguration(configuration);

    exporter.exportReport();

    System.err.println("XLSX creation time : " + (System.currentTimeMillis() - start));
  }
  public void xlsx() throws JRException {
    long start = System.currentTimeMillis();
    File sourceFile = new File(TMP_DIR + ALL_CHARTS_REPORT_JRPRINT);
    Map<String, String> dateFormats = new HashMap<String, String>();
    dateFormats.put("EEE, MMM d, yyyy", "ddd, mmm d, yyyy");
    JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(sourceFile);
    File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xlsx");

    JRXlsxExporter exporter = new JRXlsxExporter();

    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));
    SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration();
    configuration.setOnePagePerSheet(true);
    configuration.setDetectCellType(true);
    configuration.setFormatPatternsMap(dateFormats);
    exporter.setConfiguration(configuration);

    exporter.exportReport();

    System.err.println("XLSX creation time : " + (System.currentTimeMillis() - start));
  }
  public void exportAsXlsx(
      String filename, AgentOrgSocProtect supervisor, AgentRecipient beneficiary)
      throws IOException, JRException, URISyntaxException {

    HttpServletResponse response =
        (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
    response.setContentType("application/vnd.ms-excel");
    final String enc = "UTF-8";
    response.setHeader(
        "Content-Disposition",
        String.format(
            "attachment; filename*=%s''%s.%s",
            enc, URLEncoder.encode(filename, enc).replace("+", "%20"), "xlsx"));

    try (ServletOutputStream outputStream = response.getOutputStream()) {
      JRXlsxExporter exporter = new JRXlsxExporter();
      exporter.setExporterInput(
          new SimpleExporterInput(createReport(Pair.of(begin, end), supervisor, beneficiary)));
      exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
      exporter.exportReport();
      outputStream.flush();
      FacesContext.getCurrentInstance().responseComplete();
    }
  }