润乾报表的API可以让开发人员在现有功能基础上根据用户需求灵活定制一些特殊的功能。而报表类提供了一个简洁的编程框架或接口。如用API读取、运算报表的整个过程用代码来实现,大概步骤如下:
//第一步:读取报表模板,把*.rpx文件读入到内存中,并实例化ReportDefine对象
String reportFile = “/reportFiles/myReport.rpx”;
ReportDefine rd = (ReportDefine)ReportUtils.read( reportFile );
//第二步:新建上下文对象,在上下文对象中设置数据源,参数等
Context context = new Context();
//设置数据源
Connection connection = null;
… …
Driver driver = (Driver) Class.forName("org.hsqldb.jdbcDriver").newInstance();
DriverManager.registerDriver(driver);
con= DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/demo","sa","");
… …
context.setConnection("defaultDS ", conn);
//设置参数
… …
context.setParamValue(paramName ,paramValue);
//第三步:运算报表,并在页面上输出报表
Engine engine = new Engine(rd,context);
IReport iReport = engine.calc();
//展现类的实例化
HtmlReport htmlReport = new HtmlReport(iReport,"reportDS.htm");
String html = htmlReport.generateHtml();
out.print( html );
从上面明显可以看出润乾报表的接口编程基本思路是:首先根据*.rpx报表文件实例化ReportDefine对象,然后准备好报表运算行时所需要的参数以及抽取数据时所用的Connection对象等,最后是运算报表,并通过展现类进行输出展现。
当然了,这只是润乾报表API中一个简单的使用介绍。