DynamicReports jasperReport 动态列

需求

给客户定制表单,有动态列需求。类似于下图


image.png

问题

iReport工具可以画出来固定列,动态列未找到解决办法。

解决办法

表单固定部分,表头,表尾都用ireport画出来,动态列用DynamicReports 实现。

//引入jar
compile group: 'ar.com.fdvs', name: 'DynamicJasper', version: '5.0.0'
public class DoctorfeesReport {

    /**
     * 报表模板
     *
     * @return
     * @throws Exception
     */
    private DynamicReport buildReport(Map fileds) throws Exception {
        FastReportBuilder builder = new FastReportBuilder();
        Font font = new Font() ;
        font.setFontName("SansSerif");
        Style style = new Style();
        style.setBackgroundColor(Color.WHITE);
        style.setBorder(new Border(0.25f,Border.BORDER_STYLE_DASHED,Color.black));
        style.setHorizontalAlign(HorizontalAlign.CENTER);
        style.setVerticalAlign(VerticalAlign.MIDDLE);
        style.setFont(font);
        builder.setDefaultStyles(style,style,style,style) ;
        for(String key : fileds.keySet()){
            builder.addColumn(key,fileds.get(key),String.class.getName(), 26,style,style) ;
        }
        builder.setUseFullPageWidth(true);

        builder.setBottomMargin(0) ;
        builder.setDetailHeight(25);
        builder.setTemplateFile("reports/test123.jrxml") ;
        DynamicReport dr = builder.build();
        return dr;
    }

    /**
     * 测试输出报表文件
     *
     * @throws Exception
     */
    public JasperReport generateJasperReport(Map fileds) throws Exception {
        DynamicReport dr = buildReport(fileds);
        JasperReport jr = DynamicJasperHelper.generateJasperReport(dr, new ClassicLayoutManager(), null);
        return jr ;
    }
}

你可能感兴趣的:(DynamicReports jasperReport 动态列)