如何将从电子表格中提取的内联图表添加到电子邮件中?

时间:2013-07-21 06:35:39

标签: google-apps-script

目标:从Google电子表格中获取现有图表,将内联添加到电子邮件中并发送。我相信GetChart类可能有所帮助,但无法弄清楚如何。

1 个答案:

答案 0 :(得分:4)

您可以get chart as imageembed it to message

简单的例子

function sendChart(){
  var dataTable = SpreadsheetApp.getActiveSpreadsheet()
                                .getDataRange()
                                .getDataTable(true);

  var chartImage = Charts.newPieChart()
                    .setTitle('Title')
                    .setDataTable(dataTable)
                    .build()
                    .getAs('image/jpeg'); //get chart as image

  MailApp.sendEmail({
    to: "example@example.com",
    subject: "Chart",
    htmlBody: "Chart! <br> <img src='cid:chartImg'> ! <br> Wow",
    inlineImages: {
        chartImg: chartImage,
    }
  });
}

我希望它有帮助=)