-
- DynamicReport dr;
- JasperReport jr;
- JasperPrint print = null;
- HashMap hm = new HashMap();
- FastReportBuilder drb = new FastReportBuilder();
-
- drb.addColumn(String ColumnName,String FieldName,String ClassName,int ValueLength);
-
- drb.setPrintColumnNames(true);
- drb.setIgnorePagination(true) ;
- drb.setMargins(0, 0, 0, 0);
- drb.setUseFullPageWidth(true);
-
- dr = drb.build();
-
- jr = DynamicJasperHelper.generateJasperReport(dr, new ClassicLayoutManager(), hm);
-
- print = JasperFillManager.fillReport(jr, hm, DataSource);
-
-
- JExcelApiExporter exporter = new JExcelApiExporter();
-
- FileOutputStream fos = new FileOutputStream(outFileName);
-
-
- exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos);
- exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
- exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileName);
- exporter.setParameter(JRXlsExporterParameter.CHARACTER_ENCODING, "GB2312");
- exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
- exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
- exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
- exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
- exporter.setParameter(JRXlsExporterParameter.IS_IGNORE_CELL_BACKGROUND, Boolean.TRUE);
- exporter.setParameter(JRXlsExporterParameter.IS_IGNORE_CELL_BORDER, Boolean.TRUE);
-
-
- exporter.exportReport();
Excel的报表就打印完毕了,其中会有一些异常需要抛出或抓取,加上即可,CSV与TXT格式大同小异,只要同上得到print对象后,创建对应报表对象,再设置一些属性即可;