您的位置:首页 > 其它

润乾报表v4-展现报表同时后台导出excel

2016-11-28 11:13 525 查看
有些客户提出需求希望在展现报表的时候,报表在后台被自动导出成excel到指定的路径,而不用手动去点击导出excel的按钮。这个需求可以用润乾的API来实现。
实现后台自动导出excel的思路为:用API读入需要导出的raq文件,然后使用API计算报表,得到计算好的IReport对象,使用这个IReport对象导出excel到指定的路径,然后用bean的方式发布报表。
实现后台自动导出excel到指定路径的jsp代码如下所示:
<%@ page contentType=”text/html;charset=GBK”%>
<%@ taglib uri=”/WEB-INF/runqianReport4.tld” prefix=”report”%>
<%@ page import=”com.runqian.report4.model.*”%>
<%@ page import=”com.runqian.report4.usermodel.*”%>
<%@ page import=”com.runqian.report4.util.*”%>
<%@ page import=”java.util.*”%>
<%@ page import=”java.sql.*”%>
<%@ page import=”java.io.*”%>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=GBK”>
<title>test</title>
</head>
<body>
<%
String reportFileHome=Context.getInitCtx().getMainDir();
String raqPath=application.getRealPath(reportFileHome);
String raq = raqPath+”/test.raq“;
String excelpath = “D:\excel\”;
ReportDefine rd = (ReportDefineReportUtils.read(raq);
Context cxt = new Context();
Engine engine = new Engine(rd,cxt);
IReport ireport = engine.calc();
ReportUtils.exportToExcel(excelpath +”test.xls”,ireport,false);
request.setAttribute(“report”,ireport);
%>
<table align=”center” width=”100%” height=”100%“>
<tr><td>
<report:html name=”report1″
srcType=”defineBean“
beanName=”report”
funcBarLocation=”top”
exceptionPage=”/jsp/myError.jsp“
/>
</td></tr>
</table>
</body>
</html>
将以上的代码保存成excel.jsp,放到应用中可以被访问到的路径下,然后在应用中直接访问这张jsp,就会发现在报表展现的同时,这张报表已经被导出到指定的路径下面了,也就是程序代码中指定的D:/excel/下面,具体的样式和情况如下图所示:



这样在展现报表的时候后台自动导出excel的功能就实现了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: