Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

335
Views
¿Cómo formatear el cuerpo del PDF para que se parezca al correo electrónico usando Google Apps Script?

El siguiente código obtiene la respuesta del formulario y la envía por correo electrónico con el cuerpo formateado de esta manera:

Pregunta/Título1

Respuesta1

Pregunta/Título2

Respuesta2

Sin embargo, el pdf creado lo muestra todo en una sola línea, así: Nuevo formulario de respuesta: Pregunta/Título1 Respuesta1 Pregunta/Título2 Respuesta2...

¿Cómo puedo crearlo para que se vea como el cuerpo del correo electrónico con formato anterior?

 function onFormSubmit(e) { // Get the response that was submitted. var formResponse = e.response; // Get the items (ie, responses to various questions) // that were submitted. var itemResponses = formResponse.getItemResponses(); // Create a variable emailBody to store the body // of the email notification to be sent. var emailBody = "New form response:\n\n"; // Put together the email body by appending all the // questions & responses to the variable emailBody. itemResponses.forEach(function(itemResponse) { var title = itemResponse.getItem().getTitle(); var response = itemResponse.getResponse(); emailBody += title + "\n" + response + "\n\n"; }); // Send the email notification using the // sendEmail() function. sendEmail(emailBody); var folderID = "SOME_FOLDERID"; var intermediate = DriveApp.createFile('New Form Response','<b>'+ emailBody +'</b>', MimeType.HTML); var blob = intermediate.getAs(MimeType.PDF); Logger.log(blob.getContentType()); var pdfFile = DriveApp.createFile(blob); DriveApp.getFolderById(folderID).addFile(pdfFile) DriveApp.getFileById(intermediate.getId()).setTrashed(true); } // A function that sends the email // notification. function sendEmail(emailBody) { MailApp.sendEmail("EMAIL_ADDRESS", "New form response", emailBody); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe usar la etiqueta <br> para sus nuevas líneas en su cuerpo de emailBody ya que está usando un tipo HTML cuando crea un archivo. Puede usar String.replaceAll() para reemplazar \n con <br> .

 //Replace all "\n" with "<br>" emailBody = emailBody.replaceAll("\n","<br>"); var intermediate = DriveApp.createFile('New Form Response','<b>'+ emailBody +'</b>', MimeType.HTML);

Producción:

ingrese la descripción de la imagen aquí

Nota:

  • En realidad, puede usar \n como salto de línea en su cuerpo html, pero debe configurarlo en css. Ver Salto de línea en HTML con '\n'
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!