如果条件插入xdocreport docx模板,则速度

时间:2014-10-04 02:01:20

标签: velocity xdocreport

审核了XDocReport wiki以获取条件文本。

https://code.google.com/p/xdocreport/wiki/DocxReportingJavaMainCondition

不清楚如何将速度模板代码嵌入到docx合并域中。

在docx中,已创建 watershare 的合并域。

上下文替换代码如下:

IContext context = report.createContext();

// populate map
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("water_share", "#if( $water_share_transfer_flag )\n"
  + "\t<strong>Velocity!</strong>\n"
  + "#end");
map.put("water_share_transfer_flag", new Boolean("true"));
context.putMap(map);

生成的docx用速度条件替换 water_share 合并域,但不替换变量water_share_transfer_flag并显示结果 Velocity !!

1 个答案:

答案 0 :(得分:0)

您可以将docx作为Velocity模板和IContext与VelocityContext进行比较。因此,如果您希望使用#if来管理条件,则不得像您一样在上下文中使用它,而是在mergefields中使用它(在docx中):

  • 使用#if创建一个包含起始条件的合并域。在您的情况下,合并域包含:

#if( $water_share_transfer_flag )

  • 添加此合并域后必须在docx中显示的内容。在你的情况下:

Velocity!

  • 在内容&#34; Velocity!&#34;之后创建第二个合并域,其中包含#end的最终条件:

#end