I would like to import a csv file into Google Sheets using Apps Script. I would like to add the csv file to be read to the existing tab "csv_data" after the last line. Can someone help me? I am a starting apps script user. Thank you in advance for your help! GJM
0
votes
1 Answers
0
votes
There is a useful method, called Utilities.parseCsv()
If your csv file is located on your Google drive, you can import and append it e.g. by attaching to your spreadsheet a bound script with the following content:
function appendCSV() {
var file = DriveApp.getFilesByName("PASTE HERE THE NAME OF YOUR CSV FILE INCLUDING EXTENSION").next();
var csvData = Utilities.parseCsv(file.getBlob().getDataAsString(),'SPECIFY HERE THE DELIMITER (OPTIONAL)');
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow=sheet.getLastRow();
sheet.getRange(lastRow, 1, csvData.length, csvData[0].length).setValues(csvData);
}