无法在 Google 脚本中 Select 文档正文
Cannot Select a Document body in Google Script
我正在尝试将文本打印到我使用 Google Apps 脚本创建的 google 文档,并且我有以下代码:
DocumentApp.openByUrl("https://docs.google.com/document/d/1YPthft_5n5TFpnN2uqwonHtxcFmI40LOoVei7N1IdXA/edit");
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var x = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
function CreateDoc(name) {
DocumentApp.create(name);
}
function rightClick(document) {
var i
for(i = 0; i < 26; i++) {
body.appendParagraph("x[i]");
}
}
rightClick();
当我 运行 出现错误时会发生什么:
TypeError: Cannot call method "getBody" of null. (line 3, file "Code")
我不明白为什么会这样或如何解决它。如果你能帮我解决它,那就太好了。
使用 openByUrl 打开文档不会使其成为活动文档。
将第一行改为
var doc = DocumentApp.openByUrl("https://docs.google.com/document/d/1YPthft_5n5TFpnN2uqwonHtxcFmI40LOoVei7N1IdXA/edit");
删除第二行。
我正在尝试将文本打印到我使用 Google Apps 脚本创建的 google 文档,并且我有以下代码:
DocumentApp.openByUrl("https://docs.google.com/document/d/1YPthft_5n5TFpnN2uqwonHtxcFmI40LOoVei7N1IdXA/edit");
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var x = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
function CreateDoc(name) {
DocumentApp.create(name);
}
function rightClick(document) {
var i
for(i = 0; i < 26; i++) {
body.appendParagraph("x[i]");
}
}
rightClick();
当我 运行 出现错误时会发生什么:
TypeError: Cannot call method "getBody" of null. (line 3, file "Code")
我不明白为什么会这样或如何解决它。如果你能帮我解决它,那就太好了。
使用 openByUrl 打开文档不会使其成为活动文档。
将第一行改为
var doc = DocumentApp.openByUrl("https://docs.google.com/document/d/1YPthft_5n5TFpnN2uqwonHtxcFmI40LOoVei7N1IdXA/edit");
删除第二行。