润乾报表v4-导出xml文件

来源:互联网 发布:数据录入员工作职责 编辑:程序博客网 时间:2024/05/16 06:34

最近一段时间在解决客户问题的过程中,有些客户想把润乾报表导出到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文件中,上面所说的需求也就实现了。

0 0
原创粉丝点击