码迷,mamicode.com
首页 > 其他好文 > 详细

DynamicReports

时间:2014-11-25 15:52:42      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   java   for   

 

 

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();
        }

    }
}

 

DynamicReports

标签:style   blog   io   ar   color   os   sp   java   for   

原文地址:http://www.cnblogs.com/vvonline/p/4120927.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!