透過Google Apps Script編寫發送Google Sheet中的Charts程式,再結合網路爬蟲技巧與Google定時執行的排程,這樣就可以每天收到自己設定的資訊了。
筆者將以下程式碼添加到 Google Spredsheet 抓 SGX 摩台未平倉量與摩台次月契約開倉成本 中,這樣每天除了 Line Notify自動發送即時資訊外,也能在信箱中一起收到 SGX 摩台未平倉量與摩台次月契約開倉成本圖 。
function emailCharts(sheet, emails, emailSubject){ var charts = sheet.getCharts(); if(charts.length==0){ MailApp.sendEmail({ to: emails, subject: "ERROR:"+emailSubject, htmlBody: "No charts in the spreadsheet"}); return; } var chartBlobs=new Array(charts.length); var emailBody="Charts"; var emailImages={}; for(var i=0;i<charts.length;i++){ var builder = charts[i].modify(); builder.setOption('vAxis.format', '#'); var newchart = builder.build(); chartBlobs[i]= newchart.getAs('image/png'); emailBody= emailBody + "<p align='center'><img src='cid:chart"+i+"'></p>"; emailImages["chart"+i]= chartBlobs[i]; } MailApp.sendEmail({ to: emails, subject: emailSubject, htmlBody: emailBody, inlineImages:emailImages}); }執行結果:
參考資料: