我创建了一个带有单个参数的简单报告。该参数在查询中使用,直接在报表设计器中执行时可以正常执行。顺便说一句,我没有在该报告中使用 JavaScript 或任何脚本。我看到有些人试图使用脚本和/或 JavaScript 传递参数来获取答案,但这不是我正在做的。我通过java传递所有参数。继续,在本报告中,我列出了活动/非活动项目。我传入“N”用于列出非活动项目,“Y”用于列出活动项目。当我尝试通过 API 传递参数时,无论我传递什么,我总是会得到一个活动项目列表。顺便说一句,“Y”是传入参数的默认值。(我正在覆盖中的默认值)下面的代码)我遇到的问题是报告似乎不想采用我设置的参数。是的,传入的变量中的值发生了变化,但报告没有反映该变化。我的代码如下。我尝试遵循此链接的建议以及如何设置参数。
http://www.eclipsezone.com/eclipse/forums/t67723.html http://www.eclipsezone.com/eclipse/forums/t67723.html
如果您转到链接,请转到#4 并查看要执行的任务列表。这就是我试图遵循的。我觉得我可能错过了一些东西。如果你能做到这一点,你能给我一些关于我所缺少的建议吗?非常感谢!
-Dale
public class ReportGenerator {
public static void main(String args[]) throws Exception{
ReportGenerator rg = new ReportGenerator();
rg.executeReport("N");
}
@SuppressWarnings({ "unchecked", "deprecation" })
public void executeReport(String activeIndicator) throws EngineException {
IReportEngine engine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:\\birt-rcp-report-designer-3_7_2\\ReportEngine");
config.setLogConfig("c:/temp/test", Level.FINEST);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
IReportRunnable reportDesign = null;
reportDesign = engine.openReportDesign("C:\\workspace\\SimpleReport\\ReportTemplates\\ItemListingReport.rptdesign");
IRunAndRenderTask task = engine.createRunAndRenderTask(reportDesign);
IGetParameterDefinitionTask parameterDefinitionTask = engine.createGetParameterDefinitionTask(reportDesign);
parameterDefinitionTask.evaluateDefaults();
HashMap<String, String> params = parameterDefinitionTask.getDefaultValues();
params.put("aIndicator", activeIndicator);
parameterDefinitionTask.setParameterValues(params);
ConnectionHelper connectionHelper = new ConnectionHelper();
task.getAppContext().put("OdaJDBCDriverPassInConnection", connectionHelper.getConnection());
PDFRenderOption options = new PDFRenderOption();
options.setOutputFormat("pdf");
options.setOutputFileName("C:\\workspace\\SimpleReport\\output\\itemListingReport.pdf");
task.setRenderOption(options);
task.run();
task.close();
engine.destroy();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
Platform.shutdown();
}
}
}
您需要在 IRunAndRenderTask 上设置参数:
IRunAndRenderTask task =
engine.createRunAndRenderTask(reportRunnable);
Map< String, Object > birtParams = ...;
task.setParameterValues( birtParams );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)