【问题标题】:replaceText Google Apps Script pass through blank values to Google Doc MergereplaceText Google Apps 脚本将空白值传递给 Google Doc Merge
【发布时间】:2020-10-26 06:03:22
【问题描述】:

我正在做类似邮件合并的事情——从谷歌表格(实际上是脚本数组)中获取值并替换谷歌文档模板中的占位符变量。我有大约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 语句。是否有一种简单的方法可以将值或空白推送到工作表(我想要一个空白通过,因为我不希望使用 {} 变量打印最终工作表)

【问题讨论】:

  • 很遗憾,我无法理解leadType = null or "" or undefined etc.a value or a blank push through to the sheet 之间的关系。例如,在您的脚本中,如何使用像 body.replaceText("{Lead Type}", leadType || ""); 这样的逻辑“或”运算符?

标签: javascript google-apps-script google-sheets google-docs


【解决方案1】:

使用 OR 运算符怎么样?

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-11
    • 1970-01-01
    • 2014-09-17
    相关资源
    最近更新 更多