-1

Converting spread sheet to PDF works awesome! but not for exel sheet.

My code: **converting spread sheet to PDF .. working great! :) **

var pdf2 = DriveApp.getFileById(newSpreadsheet2.getId()).getAs('application/pdf').getBytes();
  var attachPdf = {fileName:'WeeklyPdfStatus.pdf',content:pdf2, mimeType:'application/pdf'};
  // Send the freshly constructed email 
  MailApp.sendEmail("<my_MailID>@gmail.com", subject, message, {attachments:[attachPdf]});
  MailApp.sendEmail("elango.vb@gmail.com", subject, message, {attachments:[attachPdf]});

My code: **converting spread sheet to Excel format .. did NOT work :( **

  var exl = DriveApp.getFileById(newSpreadsheet2.getId()).getAs('application/xls').getBlob();
  var attachExl = {fileName:'WeeklyExcelStatus.xls',content:exl, mimeType:'application/xls'};
  // Send the freshly constructed email 
  MailApp.sendEmail("<my_MailID>@gmail.com", subject, message, {attachments:[attachExl]});

I know I'm missing something basic, can some one please explain what should I change/modify so that I can get my data as excel itself?

Please help!!

Thanks in advance...

r r
  • 1
  • Thanks "Pnuts" ... I'm new to this process so please excuse. Any suggestion on how to get the spreadsheet attached as excel in mail? – r r Aug 11 '16 at 05:05

1 Answers1

0

Thanks to those who attempted to help! I did it myself after some struggle :)

did some search (Got some clue from THIS) and finally tried using URL fetch as shown below...

var file = Drive.Files.get(''); var response = UrlFetchApp.fetch('https://docs.google.com/spreadsheets/d//export?format=xlsx',{headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}});
var doc = response.getBlob(); app = DriveApp.createFile(doc).setName(file.title + '.xlsx') MailApp.sendEmail("@domain.com", "Hey XLS attached", "Please check your attachment after download and confirm", { attachments: app })

Please note: This work as on today (Aug/2016) and I'm sending email from my g-mail and spreadsheet is in my (same) g-mail drive.

I'm not sure about how to do Auth2 etc., as I exhausted all possible trials and finally got what I need, using this above URL fetch command.

Nandri! (Thank You)

Community
  • 1
  • 1
r r
  • 1