function createDocument() { var headers = Sheets.Spreadsheets.Values.get('', 'A2:I2'); var tactics = Sheets.Spreadsheets.Values.get('', 'A3:I6'); var templateId = ''; for(var i = 0; i < tactics.values.length; i++){ var company = tactics.values[i][0]; //Make a copy of the template file var documentId = DriveApp.getFileById(templateId).makeCopy().getId(); //Rename the copied file DriveApp.getFileById(documentId).setName('Propuesta de Marketing Digital para ' + company + ' 2018'); //Get the document body as a variable var body = DocumentApp.openById(documentId).getBody(); //Insert the company name body.replaceText('##Company##', company) //Append tactics parseTactics(headers.values[0], tactics.values[i], body); } } function parseTactics(headers, tactics, body){ for(var i = 1; i < tactics.length; i++){ {tactics[i] != '' && body.appendListItem(headers[i] + ' | ' + tactics[i] + ' netos').setGlyphType(DocumentApp.GlyphType.BULLET); } } }