直接在 Google Drive 文件夹中创建 Google Doc 文件 [英] Create a Google Doc file directly in a Google Drive folder

查看:16
本文介绍了直接在 Google Drive 文件夹中创建 Google Doc 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Google Drive 文件夹中创建 Google 文档?

How do I create a Google document in a Google Drive folder?

我知道我可以在这样的文件夹中创建文件.

I know that I can create a file in a folder like this.

var folder = DriveApp.createFolder("A Folder")
folder.createFile("filename.file", "Some text")

但是如何使用 Google Apps 脚本在文件夹中创建 文档.

But how I can create a document in a folder using Google Apps Script.

推荐答案

另一个答案是正确的,但该文件将存在于您的文件夹 AND 在您的驱动器"文件夹(根文件夹)中.

The other answer is correct but the file will exist in your folder AND in your "drive" folder (the root folder).

为避免这种情况,只需将其从那里删除!

To avoid that, simply remove it from there !

代码:

  var doc = DocumentApp.create('Document Name'),
      docFile = DriveApp.getFileById( doc.getId() );
  DriveApp.getFolderById('0B3°°°°°°°1lXWkk').addFile( docFile );
  DriveApp.getRootFolder().removeFile(docFile);

这篇关于直接在 Google Drive 文件夹中创建 Google Doc 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆