zoukankan      html  css  js  c++  java
  • DynamicReports 导出Excel 例子

    import java.awt.Color;
    import java.io.FileOutputStream;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
    import net.sf.dynamicreports.report.builder.DynamicReports;
    import net.sf.dynamicreports.report.builder.column.Columns;
    import net.sf.dynamicreports.report.builder.component.Components;
    import net.sf.dynamicreports.report.builder.datatype.DataTypes;
    import net.sf.dynamicreports.report.builder.style.StyleBuilder;
    import net.sf.dynamicreports.report.constant.HorizontalAlignment;
    
    public class DynamicReportsDemo {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
    
            JasperReportBuilder report = DynamicReports.report();// 创建空报表
            // 样式
            StyleBuilder boldStl = DynamicReports.stl.style().bold();
            StyleBuilder boldCenteredStl = DynamicReports.stl.style(boldStl)
                    .setHorizontalAlignment(HorizontalAlignment.CENTER);
            StyleBuilder titleStl = DynamicReports.stl.style(boldCenteredStl)
                    .setFontSize(16);
            StyleBuilder columnTitleStl = DynamicReports.stl.style(boldCenteredStl)
                    .setBorder(DynamicReports.stl.pen1Point())
                    .setBackgroundColor(Color.LIGHT_GRAY);
    
            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", 123);
            map.put("code", "185");
            map.put("service", "中国移动");
            map.put("province", "重庆");
            map.put("city", "重庆");
            map.put("type", "apple");
            map.put("name", "测试");
            list.add(map);
    
            report.columns(
                    Columns.column("ID", "id", DataTypes.integerType())
                            .setHorizontalAlignment(HorizontalAlignment.CENTER),//
                    Columns.column("手机号段", "code", DataTypes.stringType()),
                    Columns.column("运营商", "service", DataTypes.stringType()),
                    Columns.column("省份", "province", DataTypes.stringType()),
                    Columns.column("城市", "city", DataTypes.stringType()),
                    Columns.column("品牌", "type", DataTypes.stringType()))
                    .setColumnTitleStyle(columnTitleStl)
                    .setHighlightDetailEvenRows(true)
                    .title(Components.text("手机号段").setStyle(titleStl))
                    // 标题
                    .pageFooter(Components.pageXofY().setStyle(boldCenteredStl))
                    .setDataSource(list);// 数据源
            try {
                // 显示报表
                // report.show();
                report.toXls(new FileOutputStream("F:/test.xls"));
                // 生成PDF文件
                // report.toPdf(new FileOutputStream("F:/test.pdf"));
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
  • 相关阅读:
    python的argparse模块
    Robotframework之SSHLibrary库
    Python 中的 getopt 模块
    Python list 列表
    Samba windows 10 share: mount error(112): Host is down
    安装两个版本的python安装包,后安装的python程序打开时闪退
    NetScaler VPX configration
    drupal smtp could not connect to smtp
    drupal7 判断用户是否具有某个权限
    微信支付报错:time_expire时间过短,刷卡至少1分钟,其他5分钟]
  • 原文地址:https://www.cnblogs.com/vvonline/p/4107465.html
Copyright © 2011-2022 走看看