I have managed to retrieve the data and append it into my sheet but I have not figured out how to exclude the header row.
function importFromCSV() {
var fileName = Browser.inputBox("Ingrese archivo en Drive a importar (ej. datosBaby.csv):");
var searchTerm = "title = '"+fileName+"'";
// search for our file
var files = DriveApp.searchFiles(searchTerm)
var csvFile = "";
// Loop through the results
while (files.hasNext()) {
var file = files.next();
// assuming the first file we find is the one we want
if (file.getName() == fileName) {
// get file as a string
csvFile = file.getBlob().getDataAsString();
break;
}
}
// parseCsv returns a [][] array and writes to the sheet
var csvData = Utilities.parseCsv(csvFile);
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
// data to a sheet
sheet.getRange(sheet.getLastRow()+1, 1, csvData.length, csvData.length).setValues(csvData);
//sheet.getRange(1, 1, csvData.length, csvData[1].length).setValues(csvData); <-- This one places txt a A1
//sheet.appendRow(csvData[1]); <-- This one does not work
}
Here is an example of what is happening: The header from the CSV import is repeated
Thanks to anyone who can point me in the right direction. I am a beginner at this.