【发布时间】:2016-01-12 14:30:15
【问题描述】:
我有一份 Google 文档,文档正文中只有一个日期。我正在尝试编写一个每 24 小时更新一次日期的脚本。
文档中的日期当前设置为“11/01/2016”作为文本,比今天(2016 年 12 月 1 日)少 1 天。我认为使用 replaceText() 会起作用。
这是我目前的脚本。
ScriptApp.newTrigger("myFunction")
.timeBased()
.atHour(24)
.everyDays(1)
.inTimezone("GMT")
function myFunction()
{
var date = Utilities.formatDate(new Date(), "GMT", "dd/MM/yyy");
var doc = DocumentApp.openById("ID of Document");
doc.replaceText(date-1,date) ;
}
我在这里做错了什么?
【问题讨论】:
-
您看到的结果与您期望看到的结果是什么? “自定义功能”与这个问题有什么关系?提示:在函数外部调用
.newTrigger()是个坏主意;每次调用脚本中的任何函数时都会调用它。
标签: replace google-apps-script google-docs