在文件夹中创建一个文档 [英] Create a document in folder

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

问题描述

我在网上搜索了所有内容,但是我没有找到如何在文件夹中创建文档。
我知道我可以在这样的文件夹中创建文件。

  var folder = DriveApp.createFolder(文件夹)
folder.createFile(filename.file,Some text)

因此,我很想知道如何在Google Apps脚本的文件夹中创建文档

另一个答案是正确的,但该文件将存在于您的drive文件夹(根文件夹)的文件夹 AND 中。

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



代码:

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


I've searched all around the web but I've not find how to create a document in a 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")

So know I'm wondering how I can create a document in a folder in Google Apps Script.

解决方案

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 !

code :

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

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

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