user3347814
user3347814

Reputation: 1133

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?

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.

Thank You Very Much!

Upvotes: 1

Views: 7421

Answers (1)

Massimo Coletti
Massimo Coletti

Reputation: 179

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.

Upvotes: 6

Related Questions