Last active
February 12, 2021 01:41
-
-
Save josuebasurto/64e4071f386f143f27e750d4190945e6 to your computer and use it in GitHub Desktop.
Como enviar un diploa en Google Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Diploma: 1eH5suWzkJ4K-......-h94FlcuY | |
function onOpen() { | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var menuEntries = [ {name: "Genera Diploma", functionName: "generaDiploma"}, | |
{name: "Genera Todos", functionName: "generaTodos"}]; | |
ss.addMenu("Generador de Diplomas", menuEntries); | |
} | |
function generaTodos(){ | |
//Browser.msgBox("Generando TODOS los diplomas"); | |
var range = SpreadsheetApp.getActiveSheet().getDataRange(); | |
var data = range.getValues(); | |
for (var i in data) { | |
if (i != "0") | |
{ | |
var Correo = data[i][3]; | |
var Persona = data[i][1] + " " + data[i][2]; | |
var posicion = Math.abs(i)+1; | |
var evalua = SpreadsheetApp.getActiveSheet().setActiveSelection("I" + posicion).getValue(); | |
if (evalua != "OK" && evalua != "Error") | |
{ | |
var envia = sendDocument(Persona, Correo); | |
SpreadsheetApp.getActiveSheet().setActiveSelection("I" + posicion).setValue(envia); | |
SpreadsheetApp.getActiveSheet().setActiveSelection("J" + posicion).setValue(Persona + " " + Correo); | |
} | |
} | |
} | |
Browser.msgBox("Enviados TODOS los Diplomas"); | |
} | |
function sendDocument(Persona, Correo) { | |
var copyId = DocsList.getFileById("1w7o2m......ahLX8") | |
.makeCopy("Diploma de " + Persona) | |
.getId(); | |
var copyDoc = DocumentApp.openById(copyId); | |
var copyBody = copyDoc.getActiveSection(); | |
copyBody.replaceText('{{nombre}}', Persona); | |
copyDoc.saveAndClose(); | |
var pdf = DocsList.getFileById(copyId).getAs("application/pdf"); | |
var subject = "[GDG Tijuana] - Tijuana Android Bootcamp Diploma"; | |
var body = "<p>Estimad@ <b>" + Persona + "</b>:</p><p>Agradecemos que hayas participado en el Android Bootcamp, te enviamos adjunto el " + | |
"diploma de participación.</p><p>De la misma forma te invitamos a formar parte de la comunidad.</p><h2>Puedes:</h2><ul><li>Asistir a " + | |
"las reuniones de organización publicadas en el sitio.</li><li>Aportar a nuestro sitio contenido de Calidad.</li><li>Aportar con " + | |
"tus proyectos que hayas tenido con tecnologías Google.</li><li>Ser <b>speaker</b> en alguno de nuestros eventos, para mostrar la " + | |
"tecnología que dominas, conoces, o quieres conocer.</li><li><b>Proponer</b> eventos.</li><li>Aportar como patrocinador o " + | |
"contactando patrocinadores.</li><li>Comentarnos temas que quieres que abordemos.</li></ul><h2>¿Dónde?</h2><ul><li>Suscribiéndote " + | |
"a nuestro sitio: <a href='http://gdg.mx'>http://gdg.mx</a></li><li>Suscribiéndote a Google Groups: " + | |
"<a href='https://groups.google.com/forum/?fromgroups=#!forum/gdgtijuana'>https://groups.google.com/forum/?fromgroups=#!forum/gdgtijuana</a>" + | |
"</li><li>Agréganos en G+: <a href='http://gplus.to/gdgtijuana'>http://gplus.to/gdgtijuana</a></li><li>Síguenos en Twitter: " + | |
"<a href='http://twitter.com/gdgtijuana'>http://twitter.com/gdgtijuana</a></li><li>Dános LIKE en Facebook: " + | |
"<a href='http://facebook.com/gdgtijuana'>http://facebook.com/gdgtijuana</a></li></ul><p>Atte:</p><h2>GDG Tijuana</h2>" + | |
"<p>Con la tecnología de: Google Apps Script + Google Docs + Google Spreadsheets + WebStorm + GDG Tijuana</p>"; | |
try | |
{ | |
MailApp.sendEmail(Correo, subject, body, {htmlBody: body, attachments: pdf}); //Produccion | |
DocsList.getFileById(copyId).setTrashed(true); | |
return "OK"; | |
} | |
catch(e) | |
{ | |
return "Error"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var inbox = '......@.......com'; | |
var testInbox = 'jbasurto@.......com'; | |
var templateId = "1uvUBC9y9-9a......8XbbfziXtq3Uw4fio"; | |
var templateIdEn = "1ENhVKhitdKoSdZQfp......cv0KCBuA5jc"; | |
var testModeOn = false; | |
function onFormSubmit(e){ | |
//Valores Iniciales | |
var folder = DriveApp.getFileById(templateIdEn).getParents().next().getId(); | |
var template = DriveApp.getFileById(templateIdEn); | |
var actualDocument = DocumentApp.openById(template.makeCopy().getId()); | |
//Info | |
var nombreEmpleado = getValue(e.values, 1) + ' ' + getValue(e.values, 2); | |
var campanaEmpleado = getValue(e.values, 5); | |
var mailBody = 'Person: ' + nombreEmpleado + ' Area: ' + campanaEmpleado + '.'; | |
var mailSubject = 'Employee Exit Poll [ ' + nombreEmpleado + ' | ' + campanaEmpleado + ' ]'; | |
//Documento | |
actualDocument.setName('Employee Exit Poll - ' + nombreEmpleado); | |
console.info('Exit of: ' + nombreEmpleado); | |
console.info('File: ' + actualDocument.getUrl()); | |
//Close and open | |
actualDocument.saveAndClose(); | |
var actualDocument = DocumentApp.openById(actualDocument.getId()); | |
//Respuestas | |
var iterations = e.values.length; | |
for(var i = 0; i < iterations; i++){ | |
var respuestaKey = '{{R' + i + '}}'; | |
actualDocument.getBody().replaceText(respuestaKey, getValue(e.values, i)); | |
} | |
//Save | |
actualDocument.saveAndClose(); | |
//Send Email | |
GmailApp.sendEmail( testModeOn ? testInbox : inbox, mailSubject, mailBody, { attachments: [actualDocument.getAs(MimeType.PDF)], name: actualDocument.getName(), noReply: true }); | |
console.info('Sent to: ' + inbox); | |
//Delete file | |
DriveApp.getFileById(actualDocument.getId()).setTrashed(true); | |
console.info('Deleted file: ' + actualDocument.getUrl()); | |
} | |
function getValue(valores, indice){ | |
var retorna = valores[indice] == null ? '' : valores[indice]; | |
return retorna; | |
} | |
function getUserTimeZone(){ | |
return CalendarApp.getTimeZone(); | |
} | |
function getDateTimeFormat(){ | |
return 'dd/MMMM/yyyy HH:mm a'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment