Reputation: 755
I'm trying to find a way to insert a row into a google spreadsheet dynamically. I have a list of objects that has all the data for every column in a row. I'm just trying to run a for loop and then send the data to the row in the spread sheet. But the spreadsheet is completely empty. So I don't know if that creates certain problems or not.
for(var j=0; j < masterList.length; j++) {
//tried this one but it didn't pan out
sheet.appendRow([ masterList[j].Date, masterList[j].Name, masterList[j].Bugs, masterList[j].Enhancements, masterList[j].Epic, masterList[j].DevOps, masterList[j].High ]);
}
Upvotes: 0
Views: 1147
Reputation: 379
Are you accessing the spreadsheet and then the sheet before trying to append it? Here is an example.
function insertData(masterList) {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheets()[0];
for(var j=0; j < masterList.length; j++) {
var ml = masterList[j];
sheet.appendRow( [ ml.Date, ml.Name, ml.Bugs, ml.Enhancements, ml.Epic, ml.DevOps, ml.High ] );
}
}
Upvotes: 2