如何用表格格式设计报表?
我有要求在ireport设计。
我有三个VO
DeliveryAllocations { private String collectorCode; private String collectorName; private String month; private List plants = new ArrayList(); with setter/getters } PlantVO{ private String plantCode; private String plantName; private String TotalWeight; private List allocations = new ArrayList(); with setter/getters } PlantAllocationVO{ private String weight; private String customerType; private String customerValue; private String comment; private String date; with setters/getters }
现在我想在表格格式的报告中显示PlantVO
两个字段和PlantVO
三个字段。
我该如何实现这一目标? 如何获取数据以设计具有此类结构的报表?
这可以通过例如使用子报表并作为数据源传递来完成
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{allocations})
示例代码:
主要报告( PlantVO.jrxml
)
子报告( PlantAllocationVO_subreport
)
使用主要代码
JasperReport report = JasperCompileManager.compileReport("PlantVO.jrxml"); Map map = new HashMap(); JasperPrint print = JasperFillManager.fillReport(report, map,new JRBeanCollectionDataSource(deliveryAllocations.getPlants())); JasperExportManager.exportReportToPdfFile(print, "PlantVO.pdf");
会产生这样的结果 :
一些设计说明:
-
我会保持正确的字段类型(例如
weight
为Double
或Integer
)并在jrxml中应用模式(参见示例),这将帮助您正确导出到excel。 -
TotalWeight
没有真正需要将其作为字段,它可以通过子报表计算并传递回主报表。
玩的开心