DocumentApp.getUi() 上下文错误的解决方法?
Workaround to DocumentApp.getUi() context error?
我正在尝试在 Google Apps 脚本中构建一个基本的 url 获取脚本,但我遇到了 DocumentApp.getUi() 函数的问题。 (注意:我知道这似乎是 How do i use DocumentApp.getui() on a new doc 的重复,但所提供的答案实际上并没有 回答 问题,它来自 2013 年)
function myFunction() {
var doc = DocumentApp.create('new_doc'); //create doc
doc.ui = DocumentApp.getUi(); // error: 'Cannot call DocumentApp.getUi() from this context.'
var vurl = ui.prompt('url');
var furl = fetch(vurl);
doc.getBody().appendParagraph(furl)
}
我知道我不能这样称呼它,正如其他答案所解释的那样,但是有没有我可以使用的解决方法或替代方法?我是唯一会使用它的人。
考虑到你是唯一一个使用它的人,忘记 DocumentApp.getUi()
并直接添加 URL 作为文字。
假设 fetch
是在您项目的其他地方定义的函数,那么
function myFunction() {
var doc = DocumentApp.create('new_doc'); //create doc
var furl = fetch(/** replace this with your URL */);
doc.getBody().appendParagraph(furl)
}
我正在尝试在 Google Apps 脚本中构建一个基本的 url 获取脚本,但我遇到了 DocumentApp.getUi() 函数的问题。 (注意:我知道这似乎是 How do i use DocumentApp.getui() on a new doc 的重复,但所提供的答案实际上并没有 回答 问题,它来自 2013 年)
function myFunction() {
var doc = DocumentApp.create('new_doc'); //create doc
doc.ui = DocumentApp.getUi(); // error: 'Cannot call DocumentApp.getUi() from this context.'
var vurl = ui.prompt('url');
var furl = fetch(vurl);
doc.getBody().appendParagraph(furl)
}
我知道我不能这样称呼它,正如其他答案所解释的那样,但是有没有我可以使用的解决方法或替代方法?我是唯一会使用它的人。
考虑到你是唯一一个使用它的人,忘记 DocumentApp.getUi()
并直接添加 URL 作为文字。
假设 fetch
是在您项目的其他地方定义的函数,那么
function myFunction() {
var doc = DocumentApp.create('new_doc'); //create doc
var furl = fetch(/** replace this with your URL */);
doc.getBody().appendParagraph(furl)
}