デスクトップ アプリケーションで BIRT レポートを使用したことがありますか。私は .NET 環境から来ており、Crystal Reports を使用してデスクトップ アプリでレポートを表示できます。サーバー環境を構築しなくてもBIRTでも可能ですか?
この目標を達成するためのアドバイスをいただけますか?
前もって感謝します。
デスクトップ アプリケーションが Eclipse リッチ クライアント プラットフォーム (RCP) を使用して作成されている場合、レポートを追加するのは簡単です。org.eclipse.birt.viewer プラグインを追加して使用するだけです。
これを説明する記事は次のとおりです。 http://digiassn.blogspot.com/2008/08/birt-launch-birt-rcp-application.html
コマンドラインからレポートを生成できるBIRTランタイムがあります。この記事を読んでください。これにより、サーバーなしでBIRTを使用できるようになります。もともと私自身の質問への答えとしてここに記されています。
はい、可能です。約1〜2年前に行ったプロジェクトで使用したので、詳細をお知らせする必要があります. (当時とは変わっているかもしれませんが)
必要なプラグインは次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="JUNIT_HOME/junit.jar" sourcepath="JUNIT_SRC_HOME/junitsrc.zip"/>
<classpathentry kind="lib" path="lib/log4j-1.2.14.jar"/>
<classpathentry kind="lib" path="lib/swt.jar"/>
<classpathentry kind="con" path="SWT_CONTAINER"/>
<classpathentry kind="lib" path="org.eclipse.birt.chart_2.1.2.v20070205-1728.jar"/>
<classpathentry kind="lib" path="org.eclipse.birt.chart.device.extension_2.1.2.v20070205-1728.jar"/>
<classpathentry kind="lib" path="org.eclipse.birt.chart.device.swt_2.1.1.v20070205-1728.jar"/>
<classpathentry kind="lib" path="org.eclipse.birt.chart.engine_2.1.2.v20070205-1728.jar" sourcepath="C:/Programme/eclipse/plugins/org.eclipse.birt.chart.source_2.2.0.v20070209/src"/>
<classpathentry kind="lib" path="org.eclipse.birt.chart.engine.extension_2.1.2.v20070205-1728.jar"/>
<classpathentry kind="lib" path="org.eclipse.birt.chart.runtime_2.1.2.v20070205-1728.jar"/>
<classpathentry kind="lib" path="org.eclipse.birt.core_2.1.2.v20070205-1728.jar"/>
<classpathentry kind="lib" path="org.eclipse.emf.common_2.2.1.v200609210005.jar"/>
<classpathentry kind="lib" path="org.eclipse.emf.ecore_2.2.1.v200609210005.jar"/>
<classpathentry kind="lib" path="org.eclipse.emf.ecore.xmi_2.2.1.v200609210005.jar"/>
<classpathentry kind="lib" path="js.jar"/>
<classpathentry kind="lib" path="com.ibm.icu_3.4.5.jar"/>
<classpathentry kind="lib" path="org.eclipse.birt.chart.ui_2.1.1.v20070205-1728.jar"/>
<classpathentry kind="lib" path="org.eclipse.birt.chart.ui.extension_2.1.2.v20070205-1728.jar"/>
<classpathentry kind="lib" path="lib/hsqldb.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
はい、可能です。ここでは、一般的な説明をいくつか示します。サーバー環境でBirtを使用しましたが、私が知る限り、レポートを希望どおりにレンダリングするためのRenderContextインターフェースがあります。
package com.passport;
import java.io.FileOutputStream;
import java.util.Collection;
import java.util.Iterator;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;
import org.eclipse.birt.report.engine.api.IParameterDefnBase;
import org.eclipse.birt.report.engine.api.IRenderOption;
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.RenderOption;
public class EngineReport {
private static final long serialVersionUID = 1L;
private IReportEngine engine=null;
private EngineConfig engineconfig = null;
private IReportEngineFactory factory = null;
private String sourceReport;
private String locationReport;
private String reportRealPath = "";
public static void main(String[] args){
EngineReport engineReport = new EngineReport();
engineReport.save("src/com/passport/report.rptdesign","c:/tmp/rep.doc");
}
private void save(String sourceReport, String locationReport) {
this.sourceReport = sourceReport;
this.locationReport = locationReport;
IReportRunnable design = null;
IRenderOption options = null;
try {
String reportFormat = locationReport.substring(locationReport.lastIndexOf('.')+1);
sourceReport = "src/com/passport/report.rptdesign";
if ((sourceReport != null && (sourceReport.length() > 0)) ) {
engineconfig = new EngineConfig();
reportRealPath = "";
Platform.startup(engineconfig);
factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(engineconfig);
design = engine.openReportDesign(reportRealPath+sourceReport);
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
IGetParameterDefinitionTask taskParam = engine.createGetParameterDefinitionTask( design );
Collection<?> params = taskParam.getParameterDefns( false );
String paramName = null;
Iterator<?> iterOuter = params.iterator( );
while ( iterOuter.hasNext( ) ) {
IParameterDefnBase param = (IParameterDefnBase) iterOuter.next( );
paramName = param.getName( );
if (paramName.equalsIgnoreCase("PR_SOME_PARAM")) {
task.setParameterValue(paramName,"someparam");
}
else if (paramName.equalsIgnoreCase("PR_SOME_PARAM_2")) {
task.setParameterValue(paramName,"someparam2");
}
}
options = new RenderOption();
options.setOutputFormat(reportFormat);
FileOutputStream fos = new FileOutputStream(locationReport);
options.setOutputStream(fos);
task.setRenderOption(options);
task.run();
task.close();
engine.destroy();
fos.close();
}
} catch(Exception e) {
System.out.println(e.toString());
}
}
}
JeditorPane でレポートのプレビューを簡単に作成できます。BIRT ランタイムをダウンロードする必要があります。その後、Eclipse フォーラムのこの投稿に投稿されたサンプル コードを試すことができます。