zoukankan      html  css  js  c++  java
  • DynamicReports

    try {
                response.setCharacterEncoding("UTF-8");
                response.setHeader("Content-disposition", "attachment;filename="
                        + URLEncoder.encode("文件名", "UTF-8") + ".xls");
                JRDataSource ds = new JRBeanCollectionDataSource(list);
                List<ColumnBuilder> columnList = new ArrayList<ColumnBuilder>();
                columnList.add(Columns
                        .column("任务单号", "TASKNUM", DataTypes.stringType())
                        .setHorizontalAlignment(HorizontalAlignment.CENTER)
                        .setWidth(150));
                columnList.add(Columns.column("任务标题", "TASKTITLE",
                        DataTypes.stringType()).setWidth(250));
                columnList.add(Columns.column("任务内容", "TASKCONTENT",
                        DataTypes.stringType()).setWidth(250));
                columnList.add(Columns.column("检查企业", "OBJECTNAME",
                        DataTypes.stringType()).setWidth(250));
                columnList.add(Columns.column("任务类型", "TASKTYPE",
                        DataTypes.stringType()));
                columnList.add(Columns.column("任务来源", "TASKSOURCENAME",
                        DataTypes.stringType()));
                columnList.add(Columns.column("开始时间", "STARTTIME",
                        DataTypes.stringType()).setWidth(120));
                columnList.add(Columns.column("截止时间", "ENDTIME",
                        DataTypes.stringType()).setWidth(120));
                columnList.add(Columns.column("紧急程度", "URGENCYNAME",
                        DataTypes.stringType()));
                columnList.add(Columns.column("发起人", "CREATERNAME",
                        DataTypes.stringType()));
                columnList.add(Columns.column("任务状态", "TASKSTATUS",
                        DataTypes.stringType()));
                DynamicreportsReport.toXlsReport(columnList, ds,
                        response.getOutputStream());
            } catch (Exception e) {
                e.printStackTrace();
            }
    import static net.sf.dynamicreports.report.builder.DynamicReports.export;
    import static net.sf.dynamicreports.report.builder.DynamicReports.report;
    
    import java.io.OutputStream;
    import java.util.List;
    
    import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
    import net.sf.dynamicreports.jasper.builder.export.JasperXlsExporterBuilder;
    import net.sf.dynamicreports.jasper.constant.JasperProperty;
    import net.sf.dynamicreports.report.builder.column.ColumnBuilder;
    import net.sf.jasperreports.engine.JRDataSource;
    
    public class DynamicreportsReport {
    
        public static void toXlsReport(List<ColumnBuilder> columnList,
                JRDataSource dataSource, OutputStream out) throws Exception {
            try {
    
                JasperXlsExporterBuilder xlsExporter = export.xlsExporter(out)
                        .setDetectCellType(true).setIgnorePageMargins(true)
                        .setWhitePageBackground(false)
                        .setRemoveEmptySpaceBetweenColumns(true);
    
                JasperReportBuilder exporterBuilder = report()
                        .addProperty(JasperProperty.EXPORT_XLS_FREEZE_ROW, "2")
                        .ignorePageWidth().ignorePagination();
    
                for (ColumnBuilder textColumnBuilder : columnList) {
                    exporterBuilder = exporterBuilder.columns(textColumnBuilder);
                }
    
                exporterBuilder.setDataSource(dataSource).toXls(xlsExporter);
    
                // out.flush();
    
            } catch (Exception e) {
                e.printStackTrace();
            }
    
        }
    }
  • 相关阅读:
    Groups And SiteGroups
    【objc】objectivec学习(1)
    【正则】正则表达式和自动机
    【android】ListView的item事件和item里面的view的事件同时存在
    【计划】rss,搜索
    【objc】Foundation Kit
    【设计】【爬虫】针对某一主题做的爬虫,使用Jsoup解析
    【java】【实践】阅读代码,一些较好的实践
    【java】【HtmlParser】HtmlParser使用
    【learn】learn1
  • 原文地址:https://www.cnblogs.com/vvonline/p/4120927.html
Copyright © 2011-2022 走看看