How to design report with tabular format?

前端 未结 1 1963
慢半拍i
慢半拍i 2020-12-10 22:50

I have a requirement to design in ireport.

I have three VOs

DeliveryAllocations {
    private String collectorCode;
    private String collectorName         


        
1条回答
  •  独厮守ぢ
    2020-12-10 23:27

    This is done by for example using a subreport and passing as datasource

    new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{allocations})

    Example code:

    Main report (PlantVO.jrxml)

    
    
        
            
        
        
        
        
        
            
                
                    
                    
                    
                
                
                    
                    
                    
                
                
                    
                    
                    
                
                
                    
                    
                    
                
                
                    
                    
                    
                
            
        
    
    

    Sub report (PlantAllocationVO_subreport)

    
    
        
        
        
            
                
                    
                    
                    
                
                
                    
                    
                    
                
            
        
    
    

    With main code

    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");
    

    Will produce this result:

    Some design notes:

    1. I would keep correct type of fields (es. weight as a Double or Integer) and apply pattern in jrxml (see example), this will help you do correct export to excel.

    2. TotalWeight there is no really need to have this as a field, it could be calculated by subreport and passed back to main report.

    Have Fun

    0 讨论(0)
提交回复
热议问题