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

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

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

    JRXlsxExporter exporter = new JRXlsxExporter();

    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());

    exporter.exportReport();

    System.err.println("XLSX creation time : " + (System.currentTimeMillis() - start));
  }
コード例 #2
0
  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));
  }
コード例 #3
0
  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));
  }
コード例 #4
0
  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();
    }
  }
コード例 #5
0
  public void xlsx() throws JRException {
    long start = System.currentTimeMillis();
    File sourceFile = new File("build/reports/FirstJasper.jrprint");

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

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

    Map dateFormats = new HashMap();
    dateFormats.put("EEE, MMM d, yyyy", "ddd, mmm d, yyyy");

    JRXlsxExporter exporter = new JRXlsxExporter();

    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
    exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
    exporter.setParameter(JRXlsExporterParameter.FORMAT_PATTERNS_MAP, dateFormats);

    exporter.exportReport();

    System.err.println("XLSX creation time : " + (System.currentTimeMillis() - start));
  }