javascript - Need google apps script to iterate through an array -
i have modified code found cannot figure out how run whole spreadsheet.
the modified code copies spreadsheet, renames based on spreadsheet , files document in appropriate folder.
function generatemonthlyreport() { var data = spreadsheetapp.openbyid(customer_spreadsheet); // fetch variable names // column names in spreadsheet var sheet = data.getsheets()[0]; var columns = getrowasarray(sheet, 1); logger.log("processing columns:" + columns); var customerdata = getrowasarray(sheet, customer_id); logger.log("processing data:" + customerdata); // assume first column holds name of customer var customername = customerdata[1]; var customercitystate = customerdata[2]; spreadsheetapp.getactivesheet().getsheetid() var target = createduplicatedocument(source_template, "csmr - " + customername + ", " + customercitystate ); logger.log("created new document"); }
not sure understood wanted final result here how loop built, create doc each row of data.
function generatemonthlyreport() { var data = spreadsheetapp.getactivespreadsheet(); // fetch variable names // column names in spreadsheet var sheet = data.getsheets()[0]; var columns = getrowasarray(sheet, 1); for(var customer=2;customer<sheet.getlastrow();customer++){ logger.log("processing row:" + customer); var customerdata = getrowasarray(sheet, customer); logger.log("processing data:" + customerdata); // assume first column holds name of customer var customername = customerdata[0]; var customercitystate = customerdata[2]; spreadsheetapp.getactivesheet().getsheetid() // var target = createduplicatedocument(source_template, "csmr - " + customername + ", " + customercitystate ); logger.log("created new document customer "+customer+' ctitle = csmr - ' + customername + ', ' + customercitystate); } } function getrowasarray(sheet, n){ var array = []; var data = sheet.getrange(n,1,1,sheet.getlastcolumn()).getvalues(); for(var c=0;c<data[0].length;c++){ array.push(data[0][c]); } return array; }
logger of test + test sheet below :
Comments
Post a Comment