function certgen() {
var sprd = SpreadsheetApp.getActive();
var sht = sprd.getSheetByName('Opportunity');
var tst = sht.getRange(15, 3).getValue();
if (tst == "") {
const googleDocTemplate = DriveApp.getFileById('xxx');
const destinationFolder = DriveApp.getFolderById('xxx')
const copy = googleDocTemplate.makeCopy(`Certificate:` + Date() , destinationFolder)
const doc = DocumentApp.openById(copy.getId())
const body = doc.getBody();
var rws = sht.getDataRange();
var nmRws = rws.getNumRows();
for (var h=2; h<nmRws; h++) {
var hdr = sht.getRange(h, 1).getValue();
var vle = sht.getRange(h, 3).getValue();
body.replaceText('{{'+hdr+'}}', vle);
}
var sht2 = sprd.getSheetByName('Program');
var rws2 = sht2.getDataRange();
var mxrw = rws2.getNumRows();
var mxcl = sht2.getMaxColumns()
var hdr3 = new Array(mxcl);