1

审查了 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!.

4

1 回答 1

1

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

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

#if( $water_share_transfer_flag )

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

Velocity!

  • 在内容“Velocity!”之后创建第二个合并字段,其中包含您的结束条件#end:

#end

于 2014-10-04T19:06:34.147 回答