簡體   English   中英

replaceText Google Apps Script 將空白值傳遞給 Google Doc Merge

[英]replaceText Google Apps Script pass through blank values to Google Doc Merge

我正在做類似郵件合並的事情——從谷歌表(實際上是腳本數組)中獲取值並替換谷歌文檔模板中的占位符變量。 我有大約 50 個這樣的。 以下是其中三個。 格式如下所示:

body.replaceText("{Property Address}", propertyAddress);
body.replaceText("{Lead Type}", leadType);
body.replaceText("{Deal Type}", dealType);

我遇到的問題有時是一個變量可能為空 - 例如, leadType為空或"" 如果它是空白的,就會發生錯誤。 我想要做的是如果leadType有一個值,然后用該值替換 Google Doc 中的{Lead Type} 否則,如果leadType = null""undefined等,則將 Google Doc 中的{Lead Type}替換為"" 我寧願不必為這 50 行中的每一行都做一個 if/then 語句。 是否有一種簡單的方法可以將一個值或一個空白推送到工作表(我想要一個空白通過,因為我不希望使用 {} 變量打印最終工作表)

使用 OR 運算符怎么樣?

body.replaceText("{Property Address}", propertyAddress || "");
body.replaceText("{Lead Type}", leadType || "");
body.replaceText("{Deal Type}", dealType || "");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM