mogsdad / SheetConverter

Google Apps Script library - interprets Google Sheets Formats, converts to formatted text or html
49 stars 26 forks source link

Unable to schedule a script for a google sheet generated by query #2

Closed amrithajayadev closed 9 years ago

amrithajayadev commented 9 years ago

I have added a trigger for scheduling mail to my script, but the trigger seems to fail. My sheet is generated by a query as below.

=Query(Sheet1!A1:E99,"Select B,C,D Where E = 'Open' Order By C,D" )

The script works fine if I run manually.Here is my script:

function ReportByMail() {

var ss= SpreadsheetApp.getActiveSpreadsheet();

var mRows = ss.getActiveSheet().getRange('F2').getValue();

var range=ss.getActiveSheet().getRange(1, 1, mRows-1, 3); var conv = SheetConverter.init(ss.getSpreadsheetTimeZone(), ss.getSpreadsheetLocale());

var html = conv.convertRange2html(range); MailApp.sendEmail("amrithajayadev@gmail.com","Daily Reminder Services","body",{htmlBody:html} ); }

mogsdad commented 9 years ago

A timed trigger will receive null when it calls SpreadsheetApp.getActiveSpreadsheet(), since there is no Sheets instance attached to it. Instead, you need to open the spreadsheet by URL or ID.