首页 > 代码库 > DynamicReports
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(); } }}
DynamicReports
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。