谷歌应用脚​​本,openByURL返回丢失的文件?

时间:2017-01-27 16:09:28

标签: file csv google-apps-script

我一直试图弄清楚为什么我的部分Google App脚本无效,但我没有想出答案。

该脚本正在从Gmail中的电子邮件下载附件CSV,并使用特定名称存储在特定文件夹中 - 这非常合适。

但后来我想编辑CSV,这就是我遇到问题的地方。

    var newFolderIterator = DriveApp.getFoldersByName(destinationFolderName)
    var newFolderId, myFileName, myFileId
    while(newFolderIterator.hasNext()) {
      newFolderId = newFolderIterator.next().getId()
      var newFileList = DriveApp.getFolderById(newFolderId).getFiles()
      while(newFileList.hasNext()) {
        myFileName = newFileList.next()
        myFileId = myFileName.getId()
        var myFileURL = myFileName.getUrl()
        Logger.log(myFileName.getId() + " " + myFileName.getName()) //Logs the ID and Name
        Logger.log(myFileURL) //Logs the URL
        var ss = SpreadsheetApp.openById(myFileName.getId()) //Error, cannot find the ID (error message: perhaps it's missing?)

      }          
    }

我也尝试过使用openByURL,但错误信息相同。

可能很容易修复,任何提示和提示都表示赞赏。

由于

1 个答案:

答案 0 :(得分:0)

此处的问题是您正在上传CSV但尝试使用SpreadsheetApp打开它。 SpreadsheetApp只能打开Goog​​le表格文档,并且您的CSV不会自动转换。

必须首先将CSV转换为Google表格文档,然后才能使用SpreadsheetApp访问它。

您可以在上传时执行此操作,但我没有亲自尝试过。这个问题看似相关:

How to automatically import data from uploaded CSV or XLS file into Google Sheets