润乾报表导出txt文件

来源:互联网 发布:excel数据比对 编辑:程序博客网 时间:2024/05/22 16:07


在润乾报表的使用过程中,许多客户希望将润乾报表展现的数据导出成txt格式的文本文件,将报表的数据导出成txt文件需要写API代码来实现。下面就用一个简单的例子,实现导出txt的功能。

实现上面提到的导出txt文件的功能,需要执行一下四个步骤:

第一步:制作一张报表

首先打开报表设计器,新建一张空白的网格式报表,报表的数据集sql如下:

SELECT 订单.订单ID,订单.货主名称,订单.货主国家,订单.运货费 FROM 订单 WHERE 订单.订单ID <10255 ORDER BY 订单.订单ID ASC

然后在单元格内写入表达式,然后这张简单的网格式报表就做好了。

第二步:编写代码和jsp实现导出txt功能

为了实现导出txt的功能,需要写JSP,在JSP中写API代码,用这张JSP来发布上面的报表。JSP的代码和注释如下:

<%@ page contentType=”text/html;charset=gb2312″ %>
<%@ page import=”java.io.*”%>
<%@ page import=”com.runqian.report4.usermodel.*”%>
<%@ page import=”com.runqian.report4.model.*”%>
<%@ page import=”com.runqian.report4.view.html.*”%>
<%@ page import=”com.runqian.report4.util.*”%>
<%@ page import=”com.runqian.report4.view.excel.*”%>
<%
//第一步,读取报表模板
InputStream fis=application.getResourceAsStream(”/reportFiles/test.raq”);
ReportDefine rd = (ReportDefine)ReportUtils.read( fis );
//第二步,运算报表
Context context = new Context();
Engine enging = new Engine( rd, context);
IReport iReport = enging.calc();
ReportUtils ruReport = new ReportUtils();
//第三步
//1、展现输出html页面
HtmlReport hReport = new HtmlReport( iReport,”report1″ );
String htmlRS = hReport.generateHtml();
out.print(htmlRS);//把html输出到浏览器,也可以报表结果保存为html文件

File fileNew = new File( “c:\\Temp\\test.html” );
FileWriter pw = new FileWriter( fileNew );
pw.write(htmlRS);
pw.flush();
//第四步导出txt文件
FileOutputStream fosReport = new FileOutputStream(”D:\\reportHome\\webapps\\demo\\test.txt”); ruReport.exportToText(fosReport,iReport);
%>

写好JSP后,保存这个JSP在\reportHome\webapps\demo\reportJsp这个目录下,保存为test.jsp

第三步:启动tomcat,发布这张报表

点击设计器右上角的图标启动tomcat,然后发布这张报表到\reportHome\webapps\demo\reportFiles目录下,保存为:test.raq

第四步:访问这张报表,并导出txt文件

打开IE浏览器,在浏览器的地址栏里输入内容:http://127.0.0.1:6001/demo/reportJsp/test.jsp,展现报表

第五步:找到txt文件

在展现报表的同时,txt文件已经被导出了,根据上面API代码的内容,txt文件被设置成导出到D:\reportHome\webapps\demo路径下

打开这个txt文件就能看见报表的数据被成功导出了。

通过以上五个步骤,快逸报表导出txt格式文件的功能就实现了。

0 0
原创粉丝点击