/**
   * @param jrxmlFileName
   * @param pdfFileName
   * @throws Exception
   */
  public static void exportJrxmlToXml(String jrxmlFileName, String xmlFileName) throws Exception {
    String tempJasperFileName = getJasperFileName(jrxmlFileName);
    String tempJrprintFileName = getJrprintFileName(jrxmlFileName);

    // 编译static.jrxml报表设计文件,生成一个static.jasper报表文件
    JasperCompileManager.compileReportToFile(URL + jrxmlFileName, URL + tempJasperFileName);
    // 编译static.jasper报表设计文件,生成一个static.jrprint报表文件
    // 填充时,直接指定一个Connection作为数据库连接
    JasperFillManager.fillReportToFile(URL + tempJasperFileName, PARAMS, CONN);

    // 使用JasperExportManager将一个JasperPrint导出成PDF文档
    JasperExportManager.exportReportToXmlFile(URL + tempJrprintFileName, URL + xmlFileName, true);
    System.out.println("成功创建了一个XML文档");
  }
Пример #2
0
  @Test
  public void testReport() throws IOException, JRException, SQLException {
    ClassPathResource resource = new ClassPathResource("reports/jdbcReport.jrxml");
    InputStream inputStream = resource.getInputStream();

    JasperReport jasperReport = JasperCompileManager.compileReport(inputStream);

    Connection conn = dataSource.getConnection();
    JasperPrint jasperPrint =
        JasperUtils.fillReport(jasperReport, new HashMap<String, Object>(), conn);
    JasperExportManager.exportReportToPdfFile(jasperPrint, "target/jdbcReport.pdf");
    JasperExportManager.exportReportToXmlFile(jasperPrint, "target/jdbcReport.xml", false);
    JasperExportManager.exportReportToHtmlFile(jasperPrint, "target/jdbcReport.html");
  }
 public void xmlEmbed() throws JRException {
   long start = System.currentTimeMillis();
   JasperExportManager.exportReportToXmlFile("build/reports/DataSourceReport.jrprint", true);
   System.err.println("XML creation time : " + (System.currentTimeMillis() - start));
 }
 public static void exportToXml(String jrprintFileName, String xmlFileName) throws Exception {
   JasperExportManager.exportReportToXmlFile(URL + jrprintFileName, URL + xmlFileName, true);
   System.out.println("成功创建了一个XML文档");
 }
 public void xml() throws JRException {
   long start = System.currentTimeMillis();
   JasperExportManager.exportReportToXmlFile("build/reports/FirstJasper.jrprint", false);
   System.err.println("XML creation time : " + (System.currentTimeMillis() - start));
 }
 public void xmlEmbed() throws JRException {
   long start = System.currentTimeMillis();
   JasperExportManager.exportReportToXmlFile(TMP_DIR + ALL_CHARTS_REPORT_JRPRINT, true);
   System.err.println("XML creation time : " + (System.currentTimeMillis() - start));
 }
  private String saveReport(JasperPrint jasperPrint, String format, String destFileName)
      throws JRException, Exception {
    String reportName = null;
    switch (Format.valueOf(format)) {
      case pdf:
        JasperExportManager.exportReportToPdfFile(jasperPrint, destFileName);
        reportName = destFileName;
        break;
      case html:
        JasperExportManager.exportReportToHtmlFile(jasperPrint, destFileName);
        reportName = createZip(destFileName);
        break;
      case xml:
        JasperExportManager.exportReportToXmlFile(jasperPrint, destFileName, true);
        reportName = createZip(destFileName);
        break;
      case csv:
        JRCsvExporter exporter = new JRCsvExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFileName);
        exporter.exportReport();
        reportName = destFileName;
        break;
      default:
        LogUtils.errorf(this, "Error Running Report: Unknown Format: %s", format);
    }

    return reportName;
  }