简体   繁体   English

使用 Google Script 创建和打开新文档

[英]Creating and opening a new Document using Google Script

I know I can use我知道我可以使用

var doc = DocumentApp.getActiveDocument();

to create a new document on GoogleDocs, but how do I create it on a specific folder?在 GoogleDocs 上创建新文档,但如何在特定文件夹中创建它?

Further more, how do I write a code to open the newly created document?此外,如何编写代码来打开新创建的文档? I´ve searched https://developers.google.com/apps-script/reference/document/document-app#create(String) , but I could not find the answer.我搜索了https://developers.google.com/apps-script/reference/document/document-app#create(String) ,但我找不到答案。

Thank You Very Much!非常感谢!

your code can get an instance of an already existing Document, and is used for script running "inside" the document (custom options, functions, etc.)您的代码可以获得现有文档的实例,并用于在文档“内部”运行的脚本(自定义选项、函数等)

To create a new document instead, use:要创建一个新文档,请使用:

// Create and open a document.
doc = DocumentApp.create('Document Name');

this works in any script.这适用于任何脚本。

To move the document on a specific folder, you have the method:要在特定文件夹上移动文档,您可以使用以下方法:

myFolder.addFile(doc);

For more info, look at DriveApp, DocumentApp, Document, File, Folder reference.有关详细信息,请查看 DriveApp、DocumentApp、Document、File、Folder 参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM