【问题标题】:Creating and opening a new Document using Google Script使用 Google Script 创建和打开新文档
【发布时间】:2014-05-06 04:46:03
【问题描述】:

我知道我可以使用

var doc = DocumentApp.getActiveDocument();

在 GoogleDocs 上创建新文档,但如何在特定文件夹中创建?

更进一步,如何编写代码来打开新创建的文档?我已经搜索过了 https://developers.google.com/apps-script/reference/document/document-app#create(String),但我找不到答案。

非常感谢!

【问题讨论】:

    标签: google-apps-script google-drive-api google-docs


    【解决方案1】:

    您的代码可以获得现有文档的实例,并用于在文档“内部”运行脚本(自定义选项、函数等)

    要改为创建新文档,请使用:

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

    这适用于任何脚本。

    要将文档移动到特定文件夹,您有以下方法:

    myFolder.addFile(doc);
    

    有关详细信息,请查看 DriveApp、DocumentApp、文档、文件、文件夹参考。

    【讨论】:

    • 有没有办法在不从文档中打开脚本的情况下运行脚本?
    • 上面的 sn-ps 可以在任何脚本上运行:DriveApp 或 DocumentApp 是独立的“工厂”类。只有像 getActiveDocument() 这样的方法只能从用户当前打开的 Document 中运行。
    • 另请参阅 this post,它解释了 Document/Spreadsheet App 和 DriveApp 中的文档 ID 之间的差异
    猜你喜欢
    • 2013-07-27
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    相关资源
    最近更新 更多