润乾V5实现展现报表的同时导出excel



一些客户提出需求希望在展现报表的时候,报表在后台被自动导出成excel到指定的路径,而不用手动去点击导出excel的按钮。这个需求可以用润乾的API来实现。

实现后台自动导出excel的思路为:用API读入需要导出的raq文件,然后使用API计算报表,得到计算好的IReport对象,使用这个IReport对象导出excel到指定的路径,然后用bean的方式发布报表。

实现后台自动导出excel到指定路径的jsp代码如下所示:


<%@ page contentType="text/html;charset=UTF-8" %>

<%@ taglib uri="/WEB-INF/raqsoftReport.tld" prefix="report" %>

<%@ page import="com.raqsoft.report.model.ReportDefine"%>

<%@ page import="com.raqsoft.report.usermodel.Context"%>

<%@ page import="com.raqsoft.report.usermodel.Engine"%>

<%@ page import="com.raqsoft.report.usermodel.IReport"%>

<%@ page import="com.raqsoft.report.util.ReportUtils"%>

<%@ page import="java.util.Enumeration"%>

<%@ page import="java.util.HashMap"%>

<html>

<body topmargin=0 leftmargin=0 rightmargin=0 bottomMargin=0 >

<%

//第一步,读取报表模板

String report = request.getParameter( "rpx" );

String reportFile=application.getRealPath("/WEB-INF/reportFiles/"+report);

HashMap map=new HashMap();

Enumeration paramNames = request.getParameterNames();

if(paramNames!=null){

    while(paramNames.hasMoreElements()){

        String paramName = (String) paramNames.nextElement();

        String paramValue=request.getParameter(paramName);

        //把参数名和参数值分别加入到hashmap的key和value里

        map.put(paramName,paramValue);

    }

}

ReportDefine rd = (ReportDefine) ReportUtils.read(reportFile);

//第二步,运算报表

Context context = new Context();

context.setParamMap(map);

Engine enging = new Engine(rd, context);

IReport iReport = enging.calc();

//导出

String fileName = "E:/123.xls";

try {

    ReportUtils.exportToExcel(fileName, iReport, true);

    

} catch (Throwable e) {

e.printStackTrace();

}

request.setAttribute("ireport",iReport);

%>

<table align=left>

       <tr><td> 

                     <report:html name="report1"

                     srcType="defineBean"

                     beanName="ireport"

                     funcBarLocation="top"

                     exceptionPage="/reportJsp/myError.jsp"

              />

       </td></tr>

</table>

</body>

</html>

将以上代码保存为 excel.jsp 文件保存到web\webapps\demo\reportJsp 这个目录下面。然后通过这个excel.jsp 去访问报表。然后在对应的目录下面查看回发现。excel文件已经保存到了对应的目录下面。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值