javascript - Google 文档脚本 addToFolder

标签 javascript google-api google-apps-script google-drive-api

我正在尝试使用 Google 文档运行脚本的功能来为新客户端创建必要的文件夹结构(将内容/图像上传到其中)。这是我迄今为止所拥有的:

/**
 * This script creates the necessary folder structure for a new client
 */
function newClientSetup() {

  var initial = DocsList.getFolder("Clients");
  var client = DocsList.addtoFolder.createFolder("Client Name");
  var file = DocsList.addtoFolder(client);

};

现在这不起作用( TypeError: Cannot call method "createFolder" of undefined. (line 7) ),但我无法弄清楚如何使用 Folder DocList内的类(class)。我看到了DocsList有一个createFolder方法,我可以使用如下:

var folder = DocsList.createFolder("Folder Name");

但我尝试从名为 Clients 的父文件夹开始(已在 Google 文档中),然后创建以下结构:

Clients
    Client Name
        Content
        Images

理想情况下,我可以运行此脚本,但传入 Client Name 的变量实际创建客户端名称,但我没有从文档中找到太多帮助。有什么建议么?谢谢!

最佳答案

以下是其工作原理的示例,请参阅评论:

function createSubFolder(subfolder) { // the argument is the name of the folder you want to create
    var parentfolder = DocsList.getFolder('Clients'); //begin in the client folder (you could also open by Id, I prefer the ID as I find it more failsafe (ID are unique, names aren't necessarily 
    var newFolder = DocsList.createFolder(subfolder); // create the new subfolder from the argument of the function
    newFolder.addToFolder(parentfolder);// add the newly created folder to 'Clients'
}   

要测试此功能,只需使用如下所示的内容:

function test(){
    createSubFolder('test');// this will create a new folder called test in your Clients folder
}

注意:要获取文件夹的 ID,请获取文件夹 URL 中的folders/后面的值。 粗体示例:https://drive.google.com/?hl=fr&tab=wo#folders/ 0B3qSFxxxxxxxxxdsMTFZMDQ

如果您有更多文件夹级别,序列可能会更长...但结构始终相同,并且每个文件夹都是唯一的。

关于javascript - Google 文档脚本 addToFolder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11548683/

相关文章:

javascript - woocommerce 产品图片不循环显示

php - 尝试验证 Google Play 上的应用内购买时出错

javascript - 如何使用 google app 脚本循环遍历 xml 文件

javascript - Google Apps 脚本文本区域

google-apps-script - 使用 google java 客户端复制电子表格后,自定义 google 应用程序脚本不起作用

javascript - 将字符串转换为 jquery 对象并从中提取数据

javascript - 常量在服务中未定义,但在另一个服务中有效

javascript - 未捕获的语法错误 : Unexpected token '<' React

Java:如何获取应用程序的 youtube 访问/刷新 token ?

android - Google Api 返回 "The API (Blogger API) is not enabled for your project.",即使我在控制台中启用了 Blogger API