当我们使用Xdocreport和velocity通过XXX.dotx模板进行时,如何在PDF中的列中显示数据

时间:2014-11-26 14:14:09

标签: java velocity xdocreport

    Java Code : 
    ==========
    List<DosData> dosData = new ArrayList<DosData>();
    DosData data1 = new DosData();
    data1.setDosStart("10/10/2014");

    DosData data2 = new DosData();
    data2.setDosStart("11/10/2014");

    DosData data3 = new DosData();
    data3.setDosStart("12/10/2014");

    dosData.add(data1);
    dosData.add(data2);
    dosData.add(data3);
    context.put("dosData", dosData);



    I should get the Result Below : 

     ---------------------------------------  
    |10/10/2014  |  11/10/2014  | 12/10/2014|
     ---------------------------------------

    I have used Below code to display : 

     ----------------------------
    |                           |
    |                           |
    |                           |
    |       «@before-cell#      |
      foreach($d in $dosData)   |
        »«$d.dosStart»«@after-  |
        cell#end»               |
    |                           |
    |                           |
    |                           |
    |                           |
     -------------------------

当我使用上面的代码时会遇到如下所示的异常:

org.apache.fop.fo.ValidationException:行中的列号或单元格数溢出了为表指定的fo:table-columns的数量。 (没有可用的上下文信息)org.apache.fop.events.ValidationExceptionFactory.createException(ValidationExceptionFactory.java:38)         at org.apache.fop.events.EventExceptionManager.throwException(EventExceptionManager.java:54)         at org.apache.fop.events.DefaultEventBroadcaster $ 1.invoke(DefaultEventBroadcaster.java:175)         在$ Proxy297.tooManyCells(未知来源)         在org.apache.fop.fo.flow.table.TableCellContainer.addTableCellChild(TableCellContainer.java:51)         at org.apache.fop.fo.flow.table.TableRow.addChildNode(TableRow.java:95)         在org.apache.fop.fo.FOTreeBuilder $ MainFOHandler.startElement(FOTreeBuilder.java:315)         在org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:171)         在org.apache.xml.serializer.ToXMLSAXHandler.closeStartTag(ToXMLSAXHandler.java:206)         at org.apache.xml.serializer.ToXMLSAXHandler.characters(ToXMLSAXHandler.java:524)         at org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.dispatchNodeData(DOM2DTM.java:1690)         at org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.dispatchCharactersEvents(DOM2DTM.java:1622)         在org.apache.xml.dtm.ref.DTMTreeWalker.dispatachChars(DTMTreeWalker.java:204)         在org.apache.xml.dtm.ref.DTMTreeWalker.startNode(DTMTreeWalker.java:333)         在org.apache.xalan.transformer.TreeWalker2Result.startNode(TreeWalker2Result.java:146)         在org.apache.xml.dtm.ref.DTMTreeWalker.traverse(DTMTreeWalker.java:114)         在org.apache.xalan.transformer.TreeWalker2Result.traverse(TreeWalker2Result.java:74)         在org.apache.xalan.templates.ElemCopyOf.execute(ElemCopyOf.java:186)         at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)         在org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)         在org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)         在org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1376)         在org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)         在org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1376)         at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)         在org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)         在org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)         在org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1376)         at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)         在org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)         在org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)         at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2270)         at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1356)         在org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)         at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1273)         at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1251)         在org.docx4j.XmlUtils.transform(XmlUtils.java:834)         在org.docx4j.XmlUtils.transform(XmlUtils.java:727)

任何人都可以帮助我,我是新手。

1 个答案:

答案 0 :(得分:0)

您似乎使用XDocReport docx-&gt; fop转换器。这个转换器只是一个POC。今天我们已经开始了:你必须使用XDocReport itext docx-&gt; pdf转换器。

首先,我建议您不要转换报告以查看生成的docx是否正常。