日期:2014-05-17 浏览次数:21100 次
List list=this.customerDao.getAllCustomer(); //得到所有客户 JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list); JasperPrint jasperPrint = JasperFillManager.fillReport( reportFilePath, parameters, ds);
public byte[] generatePDF(String begCustNo, String endCustNo, String reportTitle, String reportFilePath) throws DemoException { // TODO Auto-generated method stub //begCustNo,endCustNo分别为查询传入的开始编号,结束编号. jdbcCustomerDao = new JdbcCustomerDao(); Map parameters = new HashMap(); parameters.put("ReportTitle", reportTitle);//报表标题 List list = jdbcCustomerDao.getAllCustomer(begCustNo, endCustNo); try { JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list); JasperPrint jasperPrint = JasperFillManager.fillReport( reportFilePath, parameters, ds); return JasperExportManager.exportReportToPdf(jasperPrint); } catch (JRException e) { throw new DemoException("Report Export Failed."); } }
String reportTitle, String reportFilePath) throws DemoException { jdbcCustomerDao = new JdbcCustomerDao(); Map parameters = new HashMap(); parameters.put("ReportTitle", reportTitle); List list = jdbcCustomerDao.getAllCustomer(begCustNo, endCustNo); System.out.println("list size is :" + list.size()); JRHtmlExporter exporter = new JRHtmlExporter(); ByteArrayOutputStream oStream = new ByteArrayOutputStream(); try { JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list); JasperPrint jasperPrint = JasperFillManager.fillReport( reportFilePath, parameters, ds); exporter.setParameter( JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE); exporter .setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter .setParameter(JRExporterParameter.CHARACTER_ENCODING, "GBK"); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, oStream); exporter.exportReport(); byte[] bytes = oStream.toByteArray(); return bytes; } catch (JRException e) { throw new DemoException("Report Export Failed."); } }
public byte[] generateExcel(String begCustNo, String endCustNo, String reportTitle, String reportFilePath) throws DemoException { jdbcCustomerDao = new JdbcCustomerDao(); Map parameters = new HashMap(); parameters.put("ReportTitle", reportTitle); List list = jdbcCustomerDao.getAllCustomer(begCustNo, endCustNo); System.out.println("list size is :" + list.size()); JRXlsExporter exporter = new JRXlsExporter(); // Excel ByteArrayOutputStream oStream = new ByteArrayOutputStream(); try { JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list); JasperPrint jasperPrint = JasperFillManager.fillReport( reportFilePath, parameters, ds); exporter .setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, oStream); exporter.setParameter( JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); exporter.setParameter( JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); exporter.exportReport(); byte[] bytes = oStream.toByteArray(); return bytes; } catch (JRException e) { throw new DemoException("Report Export Failed."); } }
<% String filePath=getServletContext().getRealPath("/")+"report.jasper"; CustomerServiceImpl custs=new C