快逸报表导出txt文件
快逸报表的使用过程中,许多客户希望将快逸报表展现的数据导出成txt格式的文本文件,将报表的数据导出成txt文件需要写API代码来实现。下面就用一个简单的例子,实现导出txt的功能。
实现上面提到的导出txt文件的功能,需要执行一下四个步骤:
第一步:制作一张报表。
首先打开报表复杂报表设计" target="_blank" class="quieeLink1">设计器,新建一张空白的网格式报表,报表的数据集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