• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

234
Views
obteniendo TypeError: no se puede leer la propiedad 'getAs' de undefined, en el script de la aplicación de Google

Estoy tratando de escribir una secuencia de comandos para enviar un correo y un pdf como archivo adjunto utilizando la secuencia de comandos de la aplicación, pero sigo recibiendo este error.

 function sendEmails() { var sheet = SpreadsheetApp.getActiveSheet(); var startRow = 2; // First row of data to process var numRows = SpreadsheetApp.getActiveSheet().getRange('I1').getValue(); // getting number of rows by fetching value from a count function in sheet var dataRange = sheet.getRange(startRow, 1, numRows, 2); // Fetch values for each row in the Range. var data = dataRange.getValues(); for (var i in data) { var row = data[i]; var emailAddress = row[0]; // First column var link = row[1];// Fetching ID by using mid fuction in sheet var file = DriveApp.getFileById(link); var subject = 'Sending emails from a Spreadsheet'; var htmlBody = DriveApp.getFileById("14KhceDa2lg7ojnwzFwpfiJCCx-xldPPj") MailApp.sendEmail(emailAddress, subject, {htmlBody: htmlBody}, {attachments: [file[0].getAs(MimeType.PDF)]}) } }

almost 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Obtiene solo el objeto de archivo usando DriveApp.getFileById , así que use file.getAs() directamente como se muestra en el código a continuación

 function sendEmails() { var sheet = SpreadsheetApp.getActiveSheet(); var startRow = 2; // First row of data to process var numRows = SpreadsheetApp.getActiveSheet().getRange('I1').getValue(); // getting number of rows by fetching value from a count function in sheet var dataRange = sheet.getRange(startRow, 1, numRows, 2); // Fetch values for each row in the Range. var data = dataRange.getValues(); for (var i in data) { var row = data[i]; var emailAddress = row[0]; // First column var link = row[1];// Fetching ID by using mid fuction in sheet var file = DriveApp.getFileById(link); var subject = 'Sending emails from a Spreadsheet'; var htmlBody = DriveApp.getFileById("14KhceDa2lg7ojnwzFwpfiJCCx-xldPPj") MailApp.sendEmail(emailAddress, subject, {htmlBody: htmlBody}, {attachments: [file.getAs(MimeType.PDF)]}) } }

almost 3 years ago · Juan Pablo Isaza Report

0

Prueba esto:

 MailApp.sendEmail(emailAddress,subject,'',{htmlBody: htmlBody,attachments: [file.getAs(MimeType.PDF)]})
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error