G.A.S. code to email a google sheet as a pdf file

2019-09-02 09:56发布

问题:

I use the following Google Script Code to generate a pdf of a google sheet and send it through email. Is there a way I can send the pdf through teleram to a person? How should I change the following code to send the pdf through telegram?

function emailReport() {
  readyForExport();
  var spreadsheet = SpreadsheetApp.getActive();
  var subject = spreadsheet.getRange("U1:U1").getValues();
  var emailTo = spreadsheet.getRange("V1:V1").getValues();
  var message = spreadsheet.getRange("W1:W1").getValues();
  var fileName = spreadsheet.getRange("X1:X1").getValues();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName("Students"));
  var pdf = DriveApp.getFileById(spreadsheet.getId()).getAs('application/pdf').getBytes();
  var attach = {fileName:fileName[0][0],content:pdf, mimeType:'application/pdf'};
  MailApp.sendEmail(emailTo, subject, message, {attachments:[attach]});
};