1

I want to import my csv as a 2d array within appscript, I don't want to export it to sheets, I just want to use the data to create google forms. The csv is located on the google drive so I want to import from my google drive into a 2d array variable.

I tried multiple attempts of similar iterations of this.

function importCSVFromGoogleDrive() {
var slotadata = Utilities.parseCsv(DriveApp.getFilesByName("Slot A.csv").next())

}

To check if it is a 2d array I logged the slotadata and its length in the logger, but it returns as [20-11-08 15:27:15:880 GMT][['Slot A.csv']]

tl;dr how to import csv from drive into variable as 2d array on GAS (Google App Script)

1 Answer 1

3

.next() is simply returning the File, but you need to get the content within the file. (Remember that Utilities.parseCsv() expects a string.) You can use getBlob() and getDataAsString() to get that content.

function importCSVFromGoogleDrive() {
  var files = DriveApp.getFilesByName("Slot A.csv");
  var firstFile = files.next(); // If there's another file called "Slot A.csv", this may not be the correct file!
  var slotadata = Utilities.parseCsv(firstFile.getBlob().getDataAsString());
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.