good_dou 2009-07-15 16:18
浏览 357
已采纳

iReport 导出word文档.doc格式 ?

怎么把iReport生成的报表导出为word文档格式.doc
我试了一下 只生成了报表图 没有文字和表格

-----------------------word
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST,jasperPrintList);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"D://allreport.doc");
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "GGB2312");
exporter.exportReport();

  • 写回答

1条回答

  • wanghaolovezlq 2009-07-15 16:25
    关注

    ireport 导出word格式
    导出word格式 在它的文档中也没有,

    // String sql = "select * from cfg_static_user_relation"; 如果传SQL语句的话用该句

    String ReportModel ="/test/test.jasper";

    File reportFile = new File(application.getRealPath(ReportModel));
    
    System.out.println(reportFile);
    if(!reportFile.exists())
         throw new JRRuntimeException("报表绘制失败,找不到报表配置文件!");
    JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());
    

    // Connection conn=null;
    // conn=JdbcConnectionFactory.getConnection();
    Collection coll = UserService.generalCollecion();
    JRDataSource sor = new JRBeanCollectionDataSource(coll);
    System.out.println(application.getRealPath("test/1224215057359.png"));
    Map parameters = new HashMap();

       parameters.put("re",application.getRealPath("test/1224215057359.png"));
    

    // JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport ,parameters,conn);

        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport ,parameters,sor);
        JRExporter exporter = new JRRtfExporter();
    
        String tmpFilename = System.currentTimeMillis() + ".doc";
    

    response.setContentType("application/msword;charset=utf-8");
    response.setHeader("Content-Disposition", "attachment; filename="+tmpFilename);

    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());

        exporter.exportReport();
    

    这样就可以导出WORD格式了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿