所以..。我试着开始使用Google脚本,使用这本书。
在第一个例子中,我遇到了一个小麻烦;我无法获得打开Google、打印问候语并关闭它的脚本。
以下是相关代码:
function helloDocument() {
var greeting = 'Hello World!';
// Create DocumentApp instance
var doc = DocumentApp.create('test_DocumentApp');
// Write the greeting to a Google Document.
doc.setText(greeting);
// Close the newly created document
doc.saveAndClose();
}对是什么阻碍我有什么想法吗?当我从脚本编辑器中选择要运行的函数时,它会显示它正在运行的消息,然后.没什么。
发布于 2016-09-04 17:32:41
您共享的代码是在Google的根文件夹中创建一个名为test_DocumentApp的文件,并在其中添加文本Hello World!。如果您找不到它,请访问、Google>最近的查看它们。看看具有类似实现的Google官方文档和视频。
我不知道你的意思是“那么.没什么。”也许你期望的结果是看到它用Google打开一个选项卡,设置文本,然后关闭它?
发布于 2016-09-04 06:15:42
你快到了。如果您正在运行独立脚本(例如,不绑定到文档),那么下面的代码应该适用于您:
function helloDocument() {
var greeting = 'Hello World!';
// Create new google doc
var doc = DocumentApp.create('test_DocumentApp');
// get the body of the document
var body = doc.getBody();
body.setText(greeting);
// Save and close the newly created document
doc.saveAndClose();
}正如尤金和其他海报所指出的,如果还没有运行脚本,则需要确保在第一次运行脚本时授予足够的权限。下面是显示工作流的屏幕截图:

单击Review Permissions。如果你的弹出窗口被阻塞了(也许是广告阻滞器?)然后,您可能还需要允许弹出该网站。

单击Accept为您的脚本授予权限。
这将运行您的代码,并在驱动器的根目录中创建一个文件。驱动并搜索名为test_DocumentApp的文件,您将看到带有问候语字符串Hello World!的文档。
https://stackoverflow.com/questions/39313222
复制相似问题