email - make a variable the text inside a cell -
i sending emails spreadsheet. want value of b2 body of email. way can type cell b2 want in message. have script set send charts , data contained in sheet, , works. when tried set body of email value of cell b2, sends message says "range" , adds charts.
my code looks far
function emailparentsupdates(sheet,emails,emailsubject){ var targetspreadsheet = spreadsheetapp.getactivespreadsheet(); var sheet = targetspreadsheet.getactivesheet(); var emailsubject = 'grades update'; var charts = sheet.getcharts(); var startrow = 1; // first row of data process var numrows = 1; // number of rows process var datarange = sheet.getrange(startrow, 1, numrows, 1) var data = datarange.getvalues(); (i in data) { var row = data[i]; var emailaddress = row[0]; // first column var teacheremail = "efazekas@dcsdk12.org" if(charts.length==0){ mailapp.sendemail({ to: teacheremail, subject: "error:"+emailsubject, htmlbody: "no charts in spreadsheet"}); return; } var chartblobs=new array(charts.length); //this issue is. need email body value, actual words, of cell b2 var emailbody = sheet.getrange('b2'); var emailimages={}; for(var i=0;i<charts.length;i++){ var builder = charts[i].modify(); builder.setoption('vaxis.format', '#'); var newchart = builder.build(); chartblobs[i]= newchart.getas('image/png'); emailbody= emailbody + "<p align='center'><img src='cid:chart"+i+"'></p>"; emailimages["chart"+i]= chartblobs[i]; } mailapp.sendemail({ to: emailaddress, subject: emailsubject, htmlbody: emailbody, inlineimages:emailimages }); } }
i know it's rough , maybe not succinct or elegant, need except whole email body issue.
function getb2value(){ var sheet = spreadsheetapp.getactivesheet(); var range = sheet.getrange('b2'); return range.getvalue(); }
getrange()
returns range, need call getvalue()
reference value of cell. i.e:
var emailbody = sheet.getrange('b2').getvalue();
Comments
Post a Comment