润乾报表api导出word



润乾报表导出word,通过api的方式,通过润乾报表提供的导出类型,实现里面的方法,具体的代码参考:

<%@ 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"%>


<%
  //创建context对象,设置报表的路径
  Context ctx = new Context();
  String path = "E:/12.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 = "E:/12.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("E:/123.doc");
  out.print("successed printout word");
  /*
  //输出到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"); 
  */
%>

可以将这个代码放在一个jsp文件中运行,直接在浏览器访问这个jsp,弹出那个成功的提示框,表是导出成功。

你可能感兴趣的:(报表应用)