多个raq导出到一个word中

在业务中,会碰到将多个报表报表展现与输出" target="_blank" class="geeznLink9">导出到一个word或excel文件中的需求

利用润乾提供的API,可以实现这样的需求

下面以两个报表导出到一个word为例,来看一下实现方法

jsp文件代码

<%@ page contentType=”text/html;charset=GBK” %>
<%@ taglib uri=”/WEB-INF/runqianReport4.tld” prefix=”report” %>
<%@ page import=”com.runqian.report4.model.ReportDefine”%>
<%@ page import=”com.runqian.report4.model.engine.ExtCellSet”%>
<%@ page import=”com.runqian.report4.usermodel.Context”%>
<%@ page import=”com.runqian.report4.usermodel.Engine”%>
<%@ page import=”com.runqian.report4.usermodel.IReport”%>
<%@ page import=”com.runqian.report4.util.ReportUtils”%>
<%@ page import=”com.runqian.report4.usermodel.PageBuilder”%>
<%@ page import=”com.runqian.report4.view.excel.ExcelReport”%>
<%@ page import=”com.runqian.report4.view.word.WordReport”%>
<%@ page import=”com.runqian.report4.usermodel.ParamMetaData”%>
<html>
<body topmargin=0 leftmargin=0 rightmargin=0 bottomMargin=0>
<%
  //创建context对象,设置报表的路径
  Context ctx = new Context();
  String path = “F:/rq4/webapps/demo/reportFiles/test1.raq”;
  //读入报表
  ReportDefine rd = (ReportDefine) ReportUtils.read(path);

  //参数传递
  ParamMetaData pmd = rd.getParamMetaData();
  String paramOrMocrName = “”;
  if(pmd != null){
   for(int i = 0, count = pmd.getParamCount(); i < count; i ++ ) {
    paramOrMocrName = pmd.getParam(i).getParamName();
    ctx.setParamValue(paramOrMocrName, request.getParameter(paramOrMocrName));
   }
  }
  
  Engine engine = new Engine(rd, ctx);
  //计算报表
  IReport report = engine.calc();
  //将报表按PrintSetup里的信息进行分页
  PageBuilder pb = new PageBuilder(report);

  Context ctx1 = new Context();
  String path1 = “F:/rq4/webapps/demo/reportFiles/test2.raq”;

  ReportDefine rd1 = (ReportDefine) ReportUtils.read(path1);
  Engine engine1 = new Engine(rd1, ctx1);
  IReport report1 = engine1.calc();
  PageBuilder pb1 = new PageBuilder(report1);  

  WordReport er = new WordReport();
  //导出到的word文件命名为moreWord.doc,依次使用export置入IReport  
  er.export(pb);
  er.export(pb1);
  //输出到指定文件
  er.saveTo(“F:/rq4/webapps/demo/jsp/moreWord.doc”);

  /*
  //输出到EXCEL
  ExcelReport er = new ExcelReport();
  //导出到的excel文件命名为moreSheetInExcel。xls,包括两个sheet,一个为one,另一个为two,保存在D盘下
  er.export(“one”, report);
  er.export(“two”, report1);
  er.saveTo(“F:/rq4/webapps/demo/jsp/moreSheetInExcel.xls”);  
  */

%>
</body>
</html>

本文标签: