heting

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  40 随笔 :: 9 文章 :: 45 评论 :: 0 Trackbacks
PDF:
(1)利用response的outputString输出:
 
            response.setContentType("application/pdf");
                   //对应报表里面的Field
                  JRBeanCollectionDataSource jrb=new JRBeanCollectionDataSource(List或Set集合);
                  //Map集合对应报表里面的Parameter
           
    byte[] pdfs=JasperRunManager.runReportToPdf(Test.class.getResourceAsStream("heting.jasper"), Map集合, jrb);
              response.getOutputStream().write(pdfs, 
0, pdfs.length);
(2)
Map parameters=new HashMap();
            parameters.put(
"today"new Date());
            List
<Users> users=Make.getList();
            JRBeanCollectionDataSource jrb
=new JRBeanCollectionDataSource(users);
             JasperPrint jasperPrint 
=
                    JasperFillManager.fillReport(Test.
class.getResourceAsStream("heting.jasper"), parameters, jrb
                    );
             
             JRXlsExporter exporter 
= new JRXlsExporter(); 
                response.reset();
                response.setContentType(
"application/vnd.ms-excel"); 
                response.setHeader(
"Content-Disposition""attachment;filename=\"aa.xls\""); 
                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.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 
                 exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, 
"GBK");
                exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,response.getOutputStream()); 

                exporter.exportReport();
HTML:


JRBeanCollectionDataSource jrb=new JRBeanCollectionDataSource(users);
             JasperPrint jasperPrint 
=
                    JasperFillManager.fillReport(Test.
class.getResourceAsStream("heting.jasper"), parameters, jrb
                    );

           JRHtmlExporter exporter = new JRHtmlExporter();
        exporter.setParameter(JRHtmlExporterParameter.OUTPUT_FILE_NAME,ls_reportname
+".htm");
        exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, 
"GBK");            
        exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, 
"<div style=\"page-break-after:always\"></div>");
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, response.getOutputStream());
            exporter.exportReport();
EXCEL
JRBeanCollectionDataSource jrb=new JRBeanCollectionDataSource(users);
             JasperPrint jasperPrint 
=
                    JasperFillManager.fillReport(Test.
class.getResourceAsStream("heting.jasper"), parameters, jrb
                    );

           JRHtmlExporter exporter = new JRHtmlExporter(); 
        response.reset();
        response.setContentType(
"application/vnd.ms-excel"); 
        response.setHeader(
"Content-Disposition""attachment;filename=\"" + ls_reportname + ".xls\""); 
        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.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 
         exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, 
"GBK");
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,response.getOutputStream()); 
            exporter.exportReport();

posted on 2008-10-22 20:10 贺挺 阅读(628) 评论(2)  编辑  收藏

评论

# re: Ireport在浏览器中的显示代码 2008-10-22 20:58 杨爱友
这东西好用吗,以前我用过,感觉挺难用的。  回复  更多评论
  

# re: Ireport在浏览器中的显示代码 2008-10-22 21:24 贺挺
@杨爱友
感觉还好,多用用就不觉的难了
  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: