2014-10-04 116 views
0

評論XDocReport wiki條件文本。速度如果條件插入到xdocreport docx模板

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

如何嵌入Velocity模板代碼到的docx合併域不明確。

在docx中,合併字段聯水收益已創建。

上下文替換代碼如下:

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和顯示結果速度!!

回答

0

您可以將您的docx作爲Velocity模板和IContext與VelocityContext進行比較。所以,如果你想使用#如果管理條件,你不能在你的環境中使用它像你這樣做,而是把它裏面MERGEFIELDS(您的DOCX內):

  • 創建其中包含與啓動條件MERGEFIELD #如果。在你的情況下,合併域包含:

#if($water_share_transfer_flag)

  • 添加哪些必須在此合併域後顯示在您的docx內容。你的情況:

Velocity!

  • 創建內容之後第二個域 「速度!」,其中包含#結束你的結束條件:

#end

+0

你建議在docx中插入mergefield,如下所示 - {MERGEFIELD「#if({MERGEFIELD $ water_share_transfer_flag})段落文本在這裏#end」}。 – 2014-10-05 23:40:06

+0

還看到了問題91,它似乎解決了類似的問題 - https://code.google.com/p/xdocreport/issues/detail?id=91 – 2014-10-06 00:12:24

+0

想通了,值應該是{MERGEFIELD「if($ condition_flag_as_boolean) 「}段落文本在這裏{MERGEFIELD #end}。感謝您的協助安傑洛 – 2014-10-06 03:23:47