0

I've been trying to figure out why part of my Google App script doesn't work, but I've failed to come up with an answer.

The script is downloading an attachment, CSV, from an email in Gmail and stores in with a specific name in a specific folder - this works perfectly fine.

But then I want to edit the CSV, and this is where I run into problems.

    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?)

      }          
    }

I've tried using the openByURL as well, with the same error message.

Probably really easy to fix, any hints and tips is appreciated.

Thanks

Andy
  • 3
  • 1

1 Answers1

0

The problem here is you are uploading a CSV but attempting to open it with SpreadsheetApp. SpreadsheetApp can only open Google Sheets documents, and your CSV is not automatically converted.

The CSV must first be converted to a Google Sheets document before you can access it with SpreadsheetApp.

You may be able to do this on upload, but I haven't tried this personally. This question looks relevant:

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

Community
  • 1
  • 1
Cameron Roberts
  • 7,127
  • 1
  • 20
  • 32