I am very new to this but would appreciate any help. I am trying to take a spreadsheet and convert the text into a doc using replace text. Everything seems to work, it creates the doc, saves it in the designated folder with the right title but none of the text is being replaced in the actual GoogleDoc.I have triple checked spelling etc but I can't seem to find the error. Pasting the entire code as I am not sure where the problem is.
function onOpen() {
const ui = SpreadsheetApp.getUi();
const menu = ui.createMenu('AutoFill Docs');
menu.addItem('Create New Docs', 'createNewGoogleDocs');
menu.addToUi();
}
function createNewGoogleDocs() {
const googleDocTemplate = DriveApp.getFileById('1UqtS6Uw4JU59IizIHZwncJjuSftKOsQH');
const destinationFolder = DriveApp.getFolderById('1avJUSvwJoA31evoNzngcLJiZfympFCWe');
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
const rows = sheet.getDataRange().getValues();
rows.forEach(function(row, index) {
if(index === 0)return;
if(row[29])return;
const copy = googleDocTemplate.makeCopy(`CC_${row[0]}_${row[1]}`, destinationFolder);
const doc = DocumentApp.openById(copy.getId());
const body = doc.getBody();
const friendlyDate = new Date(row[4]).toLocaleDateString();
body.replaceText('{{Full Name}}',row[0]);
body.replaceText('{{Position}}',row[1]);
body.replaceText('{{Yrs of Experience}}',row[2]);
body.replaceText('{{Nationality}}',row[3]);
body.replaceText('{{Date of Birth}}',friendlyDate);
body.replaceText('{{Languages}}',row[5]);
body.replaceText('{{Profile Summary}}',row[6]);
body.replaceText('{{Qualifications}}',row[7]);
body.replaceText('{{Skills}}',row[8]);
body.replaceText('{{Emp1 Date}}',row[9]);
body.replaceText('{{Emp1 Name}}',row[10]);
body.replaceText('{{Emp1 Position}}',row[11]);
body.replaceText('{{Emp1 Resp}}',row[12]);
body.replaceText('{{Emp2 Date}}',row[13]);
body.replaceText('{{Emp2 Name}}',row[14]);
body.replaceText('{{Emp2 Position}}',row[15]);
body.replaceText('{{Emp2 Resp}}',row[16]);
body.replaceText('{{Emp3 Date}}',row[17]);
body.replaceText('{{Emp3 Name}}',row[18]);
body.replaceText('{{Emp3 Position}}',row[19]);
body.replaceText('{{Emp3 Resp}}',row[20]);
body.replaceText('{{Emp4 Date}}',row[21]);
body.replaceText('{{Emp4 Name}}',row[22]);
body.replaceText('{{Emp4 Position}}',row[23]);
body.replaceText('{{Emp4 Resp}}',row[24]);
body.replaceText('{{Emp5 Date}}',row[25]);
body.replaceText('{{Emp5 Name}}',row[26]);
body.replaceText('{{Emp5 Position}}',row[27]);
body.replaceText('{{Emp5 Resp}}',row[28]);
doc.saveAndClose();
const url = doc.getUrl();
sheet.getRange(index+1,29).setValue(url);
})
}
I am trying to take a spreadsheet and convert the text into a doc using replace text.
I reduced the size of the code but left it mostly intact. I did eliminate the headers from the beginning so skipping over them was no longer necessary. And I found that the code worked with no problems