将.jrxml文件用于Swing应用程序

时间:2013-08-29 04:36:19

标签: java swing jasper-reports

实际上我正在使用.jrxml文件进行Web应用程序,但现在我需要在Swing中使用它。

有可能吗?我可以将.jrxml文件用于Swing应用程序吗?

JRXML E.G。

SELECT R.FUND_TRANSFER_TRACE_ID AS Stan_ID, FS.SERVICE_NAME, R.MOBILE_NUMBER,CASE WHEN     C.MIDDLE_NAME IS NOT NULL 
THEN (C.FIRST_NAME +' '+C.MIDDLE_NAME+' '+C.LAST_NAME) ELSE (C.FIRST_NAME +'  '+C.LAST_NAME) END AS CUSTOMER_NAME,
R.FROM_ACCOUNT, R.TO_ACCOUNT, R.AMOUNT, R.SERVICE_ATTRIBUTE, R.RECORDED_DATE AS   TRANSACTION_DATE,FTD.FONEPAY_TRACE_ID, 
FTC.RESPONSE_CODE AS CANCELATION_RESPONSE_CODE, FTC.RESPONSE_MESSAGE AS   CANCELATION_RESPONSE_DESCRIPTION,FTC.RECORDED_DATE AS CANCELED_DATE, 
FTC.REMARKS 
FROM FONEPAY_TRANSACTION_CANCELLATION FTC 
JOIN FONEPAY_TRANSACTION_DETAILS FTD ON(FTD.ID=FTC.FONEPAY_TRANSACTION_DETAILS_ID) 
JOIN REQUEST R on(FTD.REQUEST_ID=R.ID)
LEFT JOIN CUSTOMER C ON(C.ID=R.CUSTOMER_ID) 
JOIN FONEPAY_SERVICE_DETAIL FSD ON(R.FONEPAY_ID=FSD.ID) 
JOIN FONEPAY_SERVICE FS ON(FSD.FONEPAY_SERVICE_ID=FS.ID)  
WHERE 
 CONVERT(VARCHAR(10),R.RECORDED_DATE,121)
     BETWEEN CONVERT(VARCHAR(10),$P{startDate},121) and     CONVERT(VARCHAR(10),$P{endDate},121)
      and $P!{queryStr} AND FTD.FONEPAY_TRANSACTION_STATUS='REVERSAL_SUCCESS'
ORDER BY R.RECORDED_DATE DESC

2 个答案:

答案 0 :(得分:4)

JRXML文件是报告的“来源”,您需要首先编译它......

protected static JasperReport compileReport() throws JRException {

    String sourceName = "/path/to/your/.jrxml";
    String destName = "/path/to/where/you/want/your.jasper";
    JasperCompileManager.compileReportToFile(sourceName, destName);
    return (JasperReport) JRLoader.loadObjectFromFile(destName);

}

一旦你有编译的报告,你需要填写它......

 Map<String, Object> mapParameters = new HashMap<String, Object>(5);
 // Fill in your parameters...
 JRDataSource dataSource = ...; // Create your data source
 JasperPrint filledReport = JasperFillManager.fillReport(report, mapParameters, dataSource);

一旦填满,你可以将其导出......

System.out.println(" --> Exporting to PDF");
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, filledReport);
exporter.setParameter(JRExporterParameter.START_PAGE_INDEX, 0);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "your.pdf");
exporter.exportReport();

System.out.println(" --> Exporting to Excel");
JRXlsxExporter excel = new JRXlsxExporter();
excel.setParameter(JRExporterParameter.JASPER_PRINT, filledReport);
excel.setParameter(JRExporterParameter.START_PAGE_INDEX, 0);
excel.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "your.xlsx");
excel.exportReport();

System.out.println(" --> Exporting to HTML");
JRHtmlExporter html = new JRHtmlExporter();
html.setParameter(JRExporterParameter.JASPER_PRINT, filledReport);
html.setParameter(JRExporterParameter.START_PAGE_INDEX, 0);
html.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "your.html");
html.exportReport();

有关提供打印预览和打印的详细信息,请查看View and Print Reports

注意:我们在打印预览组件方面遇到了问题,最终编写了我们自己的(基于可用的来源),但从那时起它可能已经开始修复......

答案 1 :(得分:3)

你肯定可以在秋千中使用jrxml文件。我已经多次使用它在我的应用程序中。我正在使用开源工具Adempiere开发ERP解决方案。

它是使用swings开发的,它广泛使用jrxml进行报告。

请参阅以下链接,这可能会有所帮助: http://community.jaspersoft.com/questions/524537/example-java-program-call-jasper-report