<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    allen
    專注于java ee技術,包括struts,jsf,webwork,spring,hibernate,ibatis
    posts - 7,  comments - 9,  trackbacks - 0

    jasperreport中可以使用List作為數據源,使用格式如下.
    List list=this.customerDao.getAllCustomer();? //得到所有客戶
    JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list);
    ???JasperPrint jasperPrint = JasperFillManager.fillReport(
    ?????reportFilePath, parameters, ds);
    得填充數據后,即可輸出顯示到PDF,Excel,Html
    到PDF:
    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.");
    ??}
    ?}
    到Html:
    public byte[] generateHtml(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());
    ??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.");
    ??}
    ?}
    到Excel:
    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.");
    ??}
    ?}

    jsp調用方法:
    ?<%
    ????
    ???
    ?String filePath=getServletContext().getRealPath("/")+"report.jasper";?

    ?CustomerServiceImpl? custs=new CustomerServiceImpl();
    ??? byte[] bytes=null;
    ? String begNo=request.getParameter("beginCustNo");
    ? String endNo=request.getParameter("endCustNo");
    ? String type=request.getParameter("type");

    ? if(type.equals("Pdf")){?
    ????? bytes=?custs.generatePDF(begNo,endNo,"客戶資料明細表",filePath);
    ? }else if(type.equals("Excel")){
    ?? bytes=custs.generateExcel(begNo,endNo,"客戶資料明細表",filePath);
    ? }else
    ???? bytes=custs.generateHtml(begNo,endNo,"客戶資料明細表",filePath);


    ?if(bytes!=null){
    ??if(type.equals("Pdf")){
    ??????? ?response.setContentType("application/pdf");
    ??}else if(type.equals("Excel")){
    ???? response.setContentType("application/vnd.ms-excel");
    ??}else
    ???response.setContentType("text/html");
    ??? response.setContentLength(bytes.length);
    ??? ServletOutputStream ouputStream = response.getOutputStream();
    ??? ouputStream.write(bytes,0,bytes.length);
    ??? ouputStream.flush();
    ??? ouputStream.close();
    ?}else
    ?{
    ??out.println("error");
    ?}
    ?

    ?

    ? %>

    posted on 2006-11-12 22:21 robbin163 閱讀(6407) 評論(6)  編輯  收藏

    FeedBack:
    # re: jasperreport生成html,Excel,PDF報表,數據源使用List
    2007-09-06 10:52 | sss
    你引的包都有那些  回復  更多評論
      
    # re: jasperreport生成html,Excel,PDF報表,數據源使用List
    2007-09-06 10:53 | sss
    能不能給完整的代碼?我也在做公司報表。需要一個完整的代碼  回復  更多評論
      
    # re: jasperreport生成html,Excel,PDF報表,數據源使用List
    2007-09-06 11:19 | sss
    還有你的“jdbcCustomerDao = new JdbcCustomerDao();”
    里面的jdbcCustomerDao 這個包引不出來呀!  回復  更多評論
      
    # re: jasperreport生成html,Excel,PDF報表,數據源使用List
    2008-05-20 09:36 | sss
    就是個垃圾!!  回復  更多評論
      
    # re: jasperreport生成html,Excel,PDF報表,數據源使用List
    2009-08-21 09:41 | 你傻啊
    你傻啊, 這是你自己定義的連接的連接數據庫的@sss
      回復  更多評論
      
    # re: jasperreport生成html,Excel,PDF報表,數據源使用List
    2009-10-28 17:23 | weijiadi
    jdbcCustomerDao 里面有些什么內容  回復  更多評論
      

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    <2009年8月>
    2627282930311
    2345678
    9101112131415
    16171819202122
    23242526272829
    303112345

    常用鏈接

    留言簿(3)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 在线观看亚洲av每日更新| 久久久久久久岛国免费播放 | 性xxxxx免费视频播放| 亚洲AV无码久久| 毛片在线全部免费观看| 国产偷v国产偷v亚洲高清| 中文字幕在线免费看| 亚洲色婷婷综合久久| 成在人线av无码免费高潮喷水 | 亚洲精品高清一二区久久| 男人免费视频一区二区在线观看| 免费一级毛片正在播放| 国产成人无码免费看片软件| 亚洲日韩国产精品第一页一区| 日本免费在线中文字幕| 亚洲网站在线免费观看| 国产一卡2卡3卡4卡无卡免费视频| 国产亚洲精品VA片在线播放| 国产精品另类激情久久久免费| 免费一级毛片在线播放放视频| 国产午夜亚洲精品国产成人小说| 亚洲精品偷拍无码不卡av| 国产免费不卡v片在线观看| 亚洲av永久中文无码精品| 亚洲国产午夜福利在线播放| 成人性生交大片免费看中文| 亚洲偷自精品三十六区| 一区二区三区亚洲视频| 久久青草精品38国产免费| 久久精品国产亚洲αv忘忧草| 免费乱理伦在线播放| 久久一区二区三区免费播放| 亚洲性无码一区二区三区| 国产精品亚洲mnbav网站 | 亚洲黄色免费电影| 亚洲日本VA中文字幕久久道具| 亚洲午夜精品久久久久久浪潮| 免费人成视频在线观看网站 | 国产亚洲精品岁国产微拍精品| 国产免费AV片在线播放唯爱网| 黄网站色成年片大免费高清|