Java Aspose DataSet.readXml生成更复杂的结构
所以我检查了Java的示例,注意到这个示例使用了来自的Java Aspose DataSet.readXml生成更复杂的结构,java,xml,dataset,aspose.words,Java,Xml,Dataset,Aspose.words,所以我检查了Java的示例,注意到这个示例使用了来自的InTableList.doc/InTableList Aspose代码 他们正在Common.java文件中手动创建数据集。 代码的小部分摘录: // Create a new data set DataSet ds = new DataSet("ds"); // Add a new table to store contracts DataTable dtContracts = new D
InTableList.doc
/InTableList
Aspose代码
他们正在Common.java文件中手动创建数据集。
代码的小部分摘录:
// Create a new data set
DataSet ds = new DataSet("ds");
// Add a new table to store contracts
DataTable dtContracts = new DataTable("Contracts");
// Add a new table to store managers
DataTable dtManagers = new DataTable("Managers");
// Add a new table to store clients
DataTable dtClients = new DataTable("Clients");
// Add columns to Managers table
dtManagers.getColumns().add("Id", int.class);
dtManagers.getColumns().add("Name");
dtManagers.getColumns().add("Age", int.class);
dtManagers.getColumns().add("Photo", byte[].class);
ds.getTables().add(dtManagers);
// Add columns to Contracts table
dtContracts.getColumns().add("Id", int.class);
dtContracts.getColumns().add("ClientId", int.class);
dtContracts.getColumns().add("ManagerId", int.class);
dtContracts.getColumns().add("Price", float.class);
dtContracts.getColumns().add("Date", Date.class);
ds.getTables().add(dtContracts);
// Add columns to Clients table
dtClients.getColumns().add("Id", int.class);
dtClients.getColumns().add("Name");
ds.getTables().add(dtClients);
ds.getRelations().add(dtClients,dtContracts, "Id","ClientId");
ds.getRelations().add(dtManagers,dtContracts, "Id","ManagerId");
单词模板是这样的:
<<foreach [m in ds.Managers]>><<[m.Name]>> <<[m.Contracts.sum(
c => c.Price)]>><</foreach>>
Total: <<[ds.Contracts.
sum(
c => c.Price)]>>
DataSet set = new DataSet("ds");
set.readXml(new ByteArrayInputStream(escaped.getBytes()));
log.info("XML " + otherXml);
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, set);//model
<< [ds.name] >> << [ds.reference] >>
Case Handler :
<< [ds.caseHandler.first().fullName] >>
<<foreach [in ds.associated]>>
(<<[code]>>) <<[title]>> <</foreach>>
我将XML加载到数据集中,如下所示:
<<foreach [m in ds.Managers]>><<[m.Name]>> <<[m.Contracts.sum(
c => c.Price)]>><</foreach>>
Total: <<[ds.Contracts.
sum(
c => c.Price)]>>
DataSet set = new DataSet("ds");
set.readXml(new ByteArrayInputStream(escaped.getBytes()));
log.info("XML " + otherXml);
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, set);//model
<< [ds.name] >> << [ds.reference] >>
Case Handler :
<< [ds.caseHandler.first().fullName] >>
<<foreach [in ds.associated]>>
(<<[code]>>) <<[title]>> <</foreach>>
问题
基础报表坚持所有内容都在“根”节点下。
显然,这是
xml标记。
我如何修改我的设置来摆脱这个额外的级别
我的问题是,我需要用一个与这个“根”相关的“foreach”来包围word文件中的所有文本
<<foreach [c in root]>>
<< [c.name] >> << [c.reference] >>
Case Handler :
<< [c.caseHandler.first().fullName] >>
<<foreach [in c.associated]>>
(<<[code]>>) <<[title]>> <</foreach>>
<</foreach>>
> >
案件处理人:
>
()
这很烦人
我当然更喜欢这样简单的东西:
<<foreach [m in ds.Managers]>><<[m.Name]>> <<[m.Contracts.sum(
c => c.Price)]>><</foreach>>
Total: <<[ds.Contracts.
sum(
c => c.Price)]>>
DataSet set = new DataSet("ds");
set.readXml(new ByteArrayInputStream(escaped.getBytes()));
log.info("XML " + otherXml);
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, set);//model
<< [ds.name] >> << [ds.reference] >>
Case Handler :
<< [ds.caseHandler.first().fullName] >>
<<foreach [in ds.associated]>>
(<<[code]>>) <<[title]>> <</foreach>>
>
案件处理人:
>
()
问题:
如何简化结构,以便仍能读取XML,但不需要word文件中的额外开销?请使用ReportingEngine.buildReport,如下所示,以获得所需的输出 模板:
我与Aspose合作,担任开发人员宣传员 请使用ReportingEngine.buildReport,如下所示,以获得所需的输出 模板:
我与Aspose合作,担任开发人员宣传员 是的,您可以从“名称”和“引用”字段中删除ds。在这种情况下,您需要使用ReportingEngine.buildReport(Document,Object[],String[])方法,如下所示 模板:
是的,您可以从“名称”和“引用”字段中删除ds。在这种情况下,您需要使用ReportingEngine.buildReport(Document,Object[],String[])方法,如下所示 模板:
非常感谢。是否也可以删除
ds
,以便直接访问变量?我们是否只使用:engine.buildReport(doc,set.getTables().get(“root”).getRows().get(0))代码>谢谢!是否也可以删除ds
,以便直接访问变量?我们是否只使用:engine.buildReport(doc,set.getTables().get(“root”).getRows().get(0))代码>