如何使用java代码访问报表中的元素
如何使用Java访问如何使用java代码访问报表中的元素,java,pentaho,Java,Pentaho,如何使用Java访问.prpt文件中的每个元素?我需要检索例如文本字段元素并用数据填充它 我试过: public static void main(String[] args) { String reportPath = "file:/home/username/reports/example_table.prpt"; try { ClassicEngineBoot.getInstance().start(); ResourceManager re
.prpt
文件中的每个元素?我需要检索例如文本字段元素并用数据填充它
我试过:
public static void main(String[] args) {
String reportPath = "file:/home/username/reports/example_table.prpt";
try {
ClassicEngineBoot.getInstance().start();
ResourceManager resourceManager = new ResourceManager();
resourceManager.registerDefaults();
Resource resource = resourceManager.createDirectly(new URL(
reportPath), MasterReport.class);
MasterReport report = (MasterReport) resource.getResource();
for(int i=0;i<report.getElementCount();i++){
System.out.println("element :"+report.getElement(i));
}
System.out.println("Element count :" + report.getElementCount());
} catch (Exception e) {
e.printStackTrace();
}
}
该报告包含2个文本字段,我正试图从java访问这些字段,并使用查询填充数据。Pentaho报告是一个树状层次结构,以MasterReport作为根元素。getElement(i)只获取父元素的直接子元素。因此,您可能需要递归地遍历所有元素。但是,应该有一个
org.pentaho.reporting.engine.classic.core.util.AbstractStructureVisitor
类,它访问报告中的所有元素。您可以扩展它并将逻辑放入inspectElement(final ReportElement)
,该方法为每个访问的元素调用。
.
然后您可以调用它的
inspect(report)
方法来完成所有工作。但我不确定3.6版本中是否存在此类。Pentaho reports是一种树状层次结构,以MasterReport作为根元素。getElement(i)只获取父元素的直接子元素。因此,您可能需要递归地遍历所有元素。但是,应该有一个org.pentaho.reporting.engine.classic.core.util.AbstractStructureVisitor
类,它访问报告中的所有元素。您可以扩展它并将逻辑放入inspectElement(final ReportElement)
,该方法为每个访问的元素调用。
.
然后您可以调用它的
inspect(report)
方法来完成所有工作。但是我不确定3.6版本中是否存在此类。您使用的是什么库?您使用的是吗?我使用pentaho classic core 3.6.1-GAT prpt是使用PRD 5.4.0创建的。1@WackyPundit你能在报告文件中添加一个小的相同部分吗?它是XML
还是其他格式?您使用的是什么库?您使用的是吗?我使用pentaho classic core 3.6.1-gat prpt是使用PRD 5.4.0创建的。1@WackyPundit你能在报告文件中添加一个小的相同部分吗?它是XML
还是其他格式?
<?xml version="1.0" encoding="UTF-8"?>
<data-definition xmlns="http://reporting.pentaho.org/namespaces/engine/classic/bundle/data/1.0">
<parameter-definition>
<list-parameter name="id" allow-multi-selection="false" strict-values="true" mandatory="true" type="java.lang.String" query="param_id_query" key-column="id" value-column="id">
<attribute namespace="http://reporting.pentaho.org/namespaces/engine/parameter-attributes/core" name="role">user</attribute>
<attribute namespace="http://reporting.pentaho.org/namespaces/engine/parameter-attributes/core" name="parameter-render-type">list</attribute>
<attribute namespace="http://reporting.pentaho.org/namespaces/engine/parameter-attributes/core" name="re-evaluate-on-failed-values">false</attribute>
<attribute namespace="http://reporting.pentaho.org/namespaces/engine/parameter-attributes/core" name="autofill-selection">false</attribute>
<attribute namespace="http://reporting.pentaho.org/namespaces/engine/parameter-attributes/core" name="label">id</attribute>
<attribute namespace="http://reporting.pentaho.org/namespaces/engine/parameter-attributes/core" name="hidden">false</attribute>
</list-parameter>
</parameter-definition>
</data-definition>