Shrikant Ravi
Shrikant Ravi

Reputation: 19

Apend CSV from gdrive

I am trying to append data from csv saved in google drive to another file in google sheets, I want to ensure that the data gets pasted without the headers. I keep getting an error.

function getCSVAndAppend(spreadsheetId, folderId, filename)

{var folder = DriveApp.getFolderById('1TMFXWDTJpwqTY0JsCefuAean4n9fWIIh');
var files = folder.getFilesByName('Dealers joined data.csv');

  var openSpreadsheet = SpreadsheetApp.openById('1E5z7Qd3KRb5geNKlQiYhliYCOtJ0A8ICmZFcUcA1-lI');

 var activeSheet = SpreadsheetApp.getActiveSheet();
if ( files.hasNext())\
{var file = files.next();
var csv = file.getBlob().getDataAsString();

var csvData = Utilities.parseCsv(csv);

var csvDataNoHeader = csvData.splice(1,csvData.length-1)

var lastrow = activeSheet.getLastRow();

 activeSheet.getRange(lastrow + 1, 1, csvData.length, csvData[0].length).setValues(csvData);
 }
}

Upvotes: 0

Views: 49

Answers (1)

Cooper
Cooper

Reputation: 64062

It's possible that there are other issues as noted by Yuri. But this splice looks incorrect to me

var csvDataNoHeader = csvData.splice(1,csvData.length-1)

I think the 1 should be zero and the other parameter should be 1 but it might actually be easier just to use shift to remove the first row. I think csvData is a 2d array.

Upvotes: 1

Related Questions