I have a script that captures information from a panel. Once the info has been entered, user clicks a Submit button and the data entered is stored in a spreadsheet that will later be used to replace some fields of a template that I have on a cell on that spreadsheet. This process is very time consuming, like around a minute to perform all this. What I was wondering is if is possible that instead of storing the data in a cell on the spreadsheet if I can use the parameters info, and replace it on the template I have. Any ideas on how to do this?
function a(e) {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var timecell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A2");
var timebval = timecell.setValue(e.parameter.Times);
var t1 = timecell.getValue();
var mincell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A3");
var minbval = mincell.setValue(e.parameter.Minutes);
var t2 = mincell.getValue();
var namecell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A4");
var nabval = namecell.setValue(e.parameter.Name);
var t3 = namecell.getValue();
var email = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A5");
var emaval = email.setValue(e.parameter.email);
var t4 = email.getValue();
var address = "albdominguez25@gmail.com";
var advancedArgs = {bcc:t4};
var emailSubject = "Test";
var emailTemplate =SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A1").getValue() ;
emailTemplate = emailTemplate.replace("TIME",t1).replace("MIN",t2).replace("EXP",t3);
MailApp.sendEmail(address, emailSubject, emailTemplate, advancedArgs);
Browser.msgBox("Your Email has been sent!");
Instead of storing something to a spreadsheet and reading back from it for each value, just directly use the value in the replace method as shown below.
If you must store these values in your spreadsheet also for later reference, it is faster to do one setValues instead of calling setValue several times. After you use the parameter info to send the email, just call this to set all the values at once: