搜尋此網誌

2017年10月13日 星期五

MS word功能變數的應用,功能變數的英文是field code

MS word功能變數的應用問題(每個子題在下方均有說明)
  1. 大家知道「功能變數」 ,「合併列印」的英文是什麼嗎??
  2. 簡單記錄一下功能變數if的應用
  3. 如果if中的條件有兩個的話要如何做呢?
  4. 如何讓沒有值的功能變數不印出空白行?
  5. 如何在「合併列印」使用「功能變數」時可以自動編號?
  6. 所有功能變數的語法
---------------------------------------------------------------
大家知道「功能變數」 ,「合併列印」的英文是什麼嗎??
  • 「功能變數」field code 是的就是field code,如此找英文資料就比較好找啦!!
  • 「合併列印」的英文是mail merge
這篇要簡單記錄一下功能變數if的應用,如果if中的條件有兩個的話要如何做呢? (實作過喲~~)
  • {IF { = OR({COMPARE{MERGEFIELD "Field_A"} = 0}, {COMPARE{MERGEFIELD "Field_B"} = "ABC_TEXT"} )} = 1 "Show成立" "Show條件不成立"}
  • {IF { = AND({COMPARE{MERGEFIELD "Field_A"} = 0}, {COMPARE{MERGEFIELD "Field_B"} = "ABC_TEXT"} )} = 1 "Show成立" "Show條件不成立"}
重點來了,多條件怎麼處理? 也許這個可以處理:
  • {IF { = {if {MERGEFIELD "Field_A"} = 0 10} + {IF {MERGEFIELD "Field_B"} = 0 10} + {IF {MERGEFIELD "Field_C"} = 0 10}} = 30 "PASS" "FAIL"}
這個最厲害...

參考macropod [Microsoft MVP - Word]寫的

You can build a multiple AND test this way:
{IF{={IF{MERGEFIELD 1}= "Y" 1 0}*{IF{MERGEFIELD 2} 2 1 0}*{IF{MERGEFIELD 3}= "text" 1 0}}= 1 "True Text" "False Text"}

Similarly, you can build a multiple OR test this way:
{IF{={IF{MERGEFIELD 1}= "Y" 1 0}+{IF{MERGEFIELD 2} 2 1 0}+{IF{MERGEFIELD 3}= "text" 1 0}} > 0 "True Text" "False Text"}

https://answers.microsoft.com/en-us/office/forum/office_2013_release-word/is-there-a-limit-to-word-2013-and-and-or/6e47059c-e851-4ac6-8750-ad58e4fd8e80?auth=1

有個老師的網站很棒,有教學~~~必看
http://thinker-evans.blogspot.tw/2014/09/office-word-200720102013_21.html

實用

如何讓沒有值的功能變數不印出空白行? 例如下面範例使用了\f switch,如果變數street_address2沒有值,它不會印出空白行,在實務上非常好用的~~~請注意下方黃色標示的說明,也可同時前加字後也加字 感謝熱心網友的PO文「Mail Merge Switches

Selective Line Break Insertion
Use \b and \f switches to insert line breaks when needed.
\b - Specifies the text to be inserted before the MERGEFIELD field if the field is not blank.
\f - Specifies the text to be inserted following the MERGEFIELD field if the field is not blank.
EXAMPLE
{MERGEFIELD street_address1}
{MERGEFIELD street_address2 \f "↲"}
{MERGEFIELD city}, {MERGEFIELD state} {MERGEFIELD zip}
 
Replace  with an actual line break (Shift-Enter)
If all fields are not blank, the result will be
123 Main
MS 123
Any Town, CA 00000
If street_address2 is blank, the result will be
123 Main
Any Town, CA 00000
Without the \f switch, there would be an empty line between street_address1 and the city/state/zip line.

請參考以下網址也有詳細說明:
Office 2010 Don't print blank lines when data fields are empty

如何在「合併列印」使用「功能變數」時可以自動編號?

可能自動編號的,使用SEQ功能變數

https://www.youtube.com/watch?v=IPuIcxXux-4
https://support.office.com/en-us/article/seq-sequence-field-062a387b-dfc9-4ef8-8235-29ee113d59be
https://stackoverflow.com/questions/33797829/ms-word-mailmerge-autonumbering-for-mergefield


參考資料

List of field codes in Word (所有功能變數的語法)