简体   繁体   中英

Getting this error: "ReferenceError: csv is not defined"

Getting error " ReferenceError: csv is not defined ". Not able to figure out the reason. Need some help solving this error.

 function csvfiletest() { var csv1 = [ ['Alan Walker', 'Singer'], ['Cristiano Ronaldo', 'Footballer'], ['Saina Nehwal', 'Badminton Player'], ['Arijit Singh', 'Singer'], ['Terence Lewis', 'Dancer'] ]; var fileName = 'Orders.csv'; DriveApp.createFile(fileName, csv1, MimeType.text/csv); }

Modification points:

  • MimeType.text/csv is MimeType.CSV .
  • When you want to create a CSV file, it is required to convert from the array to the CSV data.

When these points are reflected in your script, it becomes as follows.

From:

DriveApp.createFile(fileName, csv1, MimeType.text/csv);

To:

DriveApp.createFile(fileName, csv1.map(r => r.join(",")).join("\n"), MimeType.CSV);

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM