通过 Google 脚本将文件添加到 Google 驱动器

Adding a file to Google Drive through Google Scripts

在一个独立的 Google 脚本中,我使用它的 API 创建了一个 Google Sheet,通过使用它的 SpreadsheetApp.create() 函数,并且用数据填充电子表格。

我必须将此文件添加到 Google 驱动器,但我不知道如何添加。我假设 create() 方法不会自动将其添加到驱动器。谢谢!

当您使用 SpreadsheetApp.create() 时,它会创建一个新的电子表格,该电子表格本机(显然)在您的云端硬盘中。没有必要将它添加到您的驱动器中,它实际上没有任何意义。 您最终可以使用这个小代码轻松检查:

function testCreate(){
  var newSs = SpreadsheetApp.create("new test spreadsheet");
  Browser.msgBox("file in drive is "+DriveApp.getFileById(newSs.getId()).getName());
}

注意:运行 这来自电子表格(任何电子表格),因为它使用仅在电子表格中有效的 Browser.msgBox() 方法。