知识库

推荐内容

快逸做的更好

产品优势

您的位置: 首页 > 知识库 > 打印专题 > 润乾报表导出xml文件

润乾报表导出xml文件

润乾报表导出 xml 文件

最近一段时间在解决客户问题的过程中,有些客户想把润乾报表导出到 xml 文件中,以方便可以在其他地方使用这些数据,而目前润乾报表没有直接可以导出 xml 的标签,所以就只能用 API 来实现将报表导出到 xml 的需求。

润乾报表的 API 中有一个 XMLReport 对象,这个对象就是处理润乾报表与 XML 文件关系的,所以要将润乾报表导出成 xml 可以从这个对象入手。下面就用润乾报表的 API 实现上面的需求。

首先读入一个报表模板 ( 报表模板的数据已经内建 ) ,然后构建报表的运算环境、设置报表授权,装载报表引擎,最后计算,生成 IReport 对象,对应的代码如下:

ReportDefine rd = (ReportDefine)ReportUtils.read(“F:/qwer.raq”);

Context ctx = new Context();

Engine engine = new Engine(rd,ctx);

ExtCellSet.setLicenseFileName(“D:/ 安装文件 / 润乾安装 /License4.0[64100621100826_640000]/ 技术应用中心专用授权 Server2010-12-31V4.0Windows.lic”);

IReport ireport = engine.calc();

然后构造一个 XMLReport 对象,把 IReport 对象写到一个本地的流中,这个流指向一个 xml 文件,对应的代码为:

XMLReport xmlreport = new XMLReport();

xmlreport.export(ireport);

FileOutputStream fos = new FileOutputStream(“F:/TEST1.xml”);

xmlreport.saveTo(fos);

fos.flush();

fos.close();

最后如果要导出 xml 的话只需要执行上面的代码就可以了,完整的 API 代码如下:

import java.io.FileOutputStream;

import com.runqian.report4.model.ReportDefine;

import com.runqian.report4.model.engine.ExtCellSet;

import com.runqian.report4.usermodel.Context;

import com.runqian.report4.usermodel.Engine;

import com.runqian.report4.usermodel.IReport;

import com.runqian.report4.util.ReportUtils;

import com.runqian.report4.view.xml.XMLReport;

public class Test

{

public export() throws Exception{

ReportDefine rd = (ReportDefine)ReportUtils.read(“F:/qwer.raq”);

Context ctx = new Context();

Engine engine = new Engine(rd,ctx);

ExtCellSet.setLicenseFileName(“D:/ 安装文件 / 润乾安装 /License4.0[64100621100826_640000]/ 技术应用中心专用授权 Server2010-12-31V4.0Windows.lic”);

IReport ireport = engine.calc();

XMLReport xmlreport = new XMLReport();

xmlreport.export(ireport);

FileOutputStream fos = new FileOutputStream(“F:/TEST1.xml”);

xmlreport.saveTo(fos);

fos.flush();

fos.close();

}

public static void main(String[] args) throws Exception {

Test test = new Test();

Test.export();

}

}

这样通过上面的代码就能把润乾报表导出到 xml 文件中,上面所说的需求也就实现了。

本文标签:
发布日期:2014/05/12
本文分类: 打印专题