审核了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 !! 。
答案 0 :(得分:0)
您可以将docx作为Velocity模板和IContext与VelocityContext进行比较。因此,如果您希望使用#if来管理条件,则不得像您一样在上下文中使用它,而是在mergefields中使用它(在docx中):
#if( $water_share_transfer_flag )
Velocity!
#end