【发布时间】:2017-01-27 12:44:39
【问题描述】:
我想从许多其他 JasperReport 创建一份报告。但我没有看到第一个 JasperPrint 之后的数据。如果我要换位置jasperPrintTracking 和jasperPrintDeparture。您将看到我首先编写的 JasperPrint 中的数据,但第二次 JasperPrint 没有任何数据。如果我一开始写jasperPrintTracking - 我会看到来自jasperPrintTracking 的数据,但是看不到来自jasperPrintDeparture 的数据,他们没有下载。为什么会这样?
public class RoadReport {
JasperPrint jasperPrintDeparture;
JasperPrint jasperPrintTracking;
CardFile cardFile = new CardFile();
public void createRoadReport (List <StatisticsOnPassengerTrainByMonth> passsenger, List<StatisticsOnCommuterTrainByMonth> commuter, List<StatisticsOnFreightTrainByMonth> freight){
JRBeanCollectionDataSource passengerDataSource = new JRBeanCollectionDataSource(passsenger);
JRBeanCollectionDataSource commuterDataSource = new JRBeanCollectionDataSource(commuter);
JRBeanCollectionDataSource freightDataSource = new JRBeanCollectionDataSource(freight);
Map <String, Object> parametr = new HashMap<String, Object>();
parametr.put("PassengerDataSource", passengerDataSource);
parametr.put("CommuterDataSource", commuterDataSource);
parametr.put("FreightDataSource", freightDataSource);
try {
jasperPrintDeparture = JasperFillManager.fillReport((FacesContext.getCurrentInstance().getExternalContext().getRealPath("/ReportRoadDeparture.jasper")), parametr, new JREmptyDataSource());
jasperPrintTracking = JasperFillManager.fillReport((FacesContext.getCurrentInstance().getExternalContext().getRealPath("/ReportRoadTracking.jasper")), parametr, new JREmptyDataSource());
multipageLinking(jasperPrintDeparture, jasperPrintTracking);
JasperExportManager.exportReportToPdfFile(jasperPrintDeparture, FacesContext.getCurrentInstance().getExternalContext().getRealPath("/report1.pdf"));
} catch (JRException e) {
e.printStackTrace();
}
}
@SuppressWarnings("rawtypes")
private JasperPrint multipageLinking(JasperPrint file1, JasperPrint file2) {
List pages = file2.getPages();
for (int count = 0; count <
pages.size(); count++) {
file1.addPage((JRPrintPage) pages.get(count));
}
return file1;
}
}
报告图片如下
【问题讨论】:
-
stackoverflow.com/a/34580248 提供了另一种合并报表的方式。也许你应该先检查一下。
标签: java jasper-reports