第一步:定义一下JAVA,class(看后面附件)
第二步:定义一个LIST
第三步:在BIRT报表的DATASET事件中(open)中输入
count = 0;
cf = new Packages.user.ContactListFactory();
c = cf.createContactList();
在BIRT报表的DATASET事件中(CLOSE)中输入
cf=null; c=null;
在BIRT报表的DATASET事件中(FETCH)中输入
if (count <= c.length-1){
row["columnFirstName"] = c[count].getFname();
row["columnLastName"] = c[count].getLname();
row["columnPhoneNumber"]= c[count].getPhone();
count ++; return true; }
return false;
-
###############################################
附件
################################################
第一二步的两个JAVA类代码发下:
A:package user;
public class Contact {
String fname;
String lname;
String phone;
public Contact(String fname, String lname, String phone){
this.fname = fname;
this.lname = lname;
this.phone = phone;
}
/*
*
* @return Returns the fname.
*/
public String getFname() {
return fname;
}
/**
* @param fname The fname to set.
*/
public void setFname(String fname) {
this.fname = fname;
}
/**
* @return Returns the lname.
*/
public String getLname() {
return lname;
}
/**
* @param lname The lname to set.
*/
public void setLname(String lname) {
this.lname = lname;
}
/**
* @return Returns the phone.
*/
public String getPhone() {
return phone;
}
/**
* @param phone The phone to set.
*/
public void setPhone(String phone) {
this.phone = phone;
}
}
B:
package user;
public class ContactListFactory {
public Contact[] createContactList(){
Contact[] c = new Contact[5];
c[0] = new Contact("stavros", "kounis", "2310886269");
c[1] = new Contact("dimitris", "kounis", "2310888270");
c[2] = new Contact("dimitris", "adamos", "2310998417");
c[3] = new Contact("nikos", "koufotolis", "2321013770");
c[4] = new Contact("yan", "liang", "13824745919");
return c;
}
}
注:发布后将两个JAVA类产生的CLASS 放在
C:\eclipse\plugins\org.eclipse.birt.report.viewer_2.1.0.N20060628-1351\birt\WEB-INF\classes\user 目录下,
USER是开发时的包
经过发上步骤,再写一个JAVA PROJECT
调用上述报表代码如下
package user;
import javax.swing.JOptionPane;
import user.ExecuteReport;
public class Reporttest {
public static void main(String args[]) {
try {
ExecuteReport mreport = new ExecuteReport();
mreport.executeReport();
}catch ( Exception e ) {
e.printStackTrace();
}
/*System.out.println("中国人民解");
JOptionPane.showMessageDialog(null,"中国人民解");
System.exit(0);
*/
}
}
主代码JAVA:
package user;
import java.util.Collection;
import java.util.HashMap;
import java.util.logging.Level;
import javax.swing.text.html.HTMLDocument.Iterator;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLActionHandler;
import org.eclipse.birt.report.engine.api.HTMLEmitterConfig;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;
import org.eclipse.birt.report.engine.api.IParameterDefnBase;
import org.eclipse.birt.report.engine.api.IParameterGroupDefn;
import org.eclipse.birt.report.engine.api.IParameterSelectionChoice;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.IScalarParameterDefn;
public class ExecuteReport {
static void executeReport() throws EngineException{
IReportEngine engine=null;
EngineConfig config = null;
try{
//Configure the Engine and start the Platform
config = new EngineConfig( );
config.setEngineHome( "C:/eclipse/workspace/ReportDrive/birt-runtime-2_1_0/ReportEngine" );
config.setLogConfig(null, Level.FINE);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
engine.changeLogLevel( Level.WARNING );
}catch( Exception ex){
ex.printStackTrace();
}
IReportRunnable design = null;
//Open the report design
design = engine.openReportDesign("C:/eclipse/workspace/html/kenScripDataset.rptdesign");
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
//Set rendering options - such as file or stream output,
//output format, whether it is embeddable, etc
HTMLRenderOption options = new HTMLRenderOption();
/**************************************************/
HashMap parameters = new HashMap();
String name = "myreportname";
String pvalue ="客户产品工序表";
parameters.put(name,pvalue);
task.setParameterValues(parameters);
task.validateParameters();
/**************************************************/
options.setOutputFileName("C:/eclipse/workspace/html/kenScripDataset.pdf");
//Set output format options.setOutputFormat("pdf");
task.setRenderOption(options);
//run the report and destroy the engine
//Note - If the program stays resident do not shutdown the Platform or the Engine
task.run();
task.close();
engine.shutdown();
Platform.shutdown();
System.out.println("Finished");
System.exit(0);
}
}
----------------------------------------
在eclispe 3.2的PATH BUILD中加入
BIRT 的com.ibm.icu_3.4.4.1 .JAR BIRT
的engineapi.JAR BIRT 的coreapi.JAR BIRT 的JS.JAR
分享到:
相关推荐
java调用远程接口传输数据的demo
数据集格式:Pascal VOC格式(不包含分割的txt文件,仅仅包含jpg图片和对应的xml) 图片数量(jpg文件个数):17000 标注数量(xml文件个数):17000 标注类别数:1 总文件大小:约4GB,分2个压缩包 标注类别名称:["bird"]...
帮助在java中调用weka中的数据集的源代码,java写的代码
使用iServer JAVA API访问iServer数据服务进行数据操作示例工程,博客地址: http://blog.csdn.net/supermapsupport/article/details/71107998
Java 反射调用设置值
java调用json参数的webservice 涉及技术: JAVA JSON WEBSERVICE
Bartender提供了.net的开发sdk,但是没有提供java的,使得java开发者调用Bartender实现模板打印比较困难。本示例是结合Bartender官方资料,利用java通过COM组件方式实现可传递参数的模板打印。
1,利用java调用soap接口获取天气的信息;2,利用java调用soap一个特定的案例,可按自己的要求修改。
java通过utgard调用OPC获取点位数据,注意要csid来获取,直接用户名和密码获取有误
java调用R语言实现数据挖掘
Xfire 调用气象数据接口 java调用天气 java气象数据接口 很好的气象数据接口 里面的UserId需要从www.36wu.com从新申请。
Java调用weka神经网络算法预测股票,含有代码及数据,代码有详细解释,数据为大量数据。
本代码主要开源了java报表工具中程序数据集和自定义函数部分的代码,通过该开源代码,你可以了解报表工具的内部原理,掌握国内主流java报表工具的各类接口使用方法,并运用该接口对软件产品或项目中的个性化的需求...
Iris数据集是常用的分类实验数据集,由Fisher, 1936收集整理。iris以鸢尾花的特征作为数据来源,常用在分类操作中。该数据集由3种 不同类型的鸢尾花的50个样本数据构成。其中的一个种类与另外两个种类是线性可分离的...
使用Java语言调用终端开启关闭Nginx服务器,然后执行ffmpeg命令,开启转流推流。以及其它指令,来学习吧
Java web 开发,Java script 脚本编写的pdf教程。开发好的网站,离不开Java。学习Java是你第一明智的选择,选择这个教程就是你第二明智的选择。
JAVA调用海康威视SDK实现摄像头预览源码
使用Java获取制定接口的数据,使用了httpserverletrequest类。
自己写的几个调用百度地图API的实用性方法 HTML和JS代码都有