How add an inline chart pulled from a spreadsheet

2019-04-13 18:25发布

Goal: take an existing chart from a Google Spreadsheet, add inline to an email and send. I believe the GetChart class may help, but cannot figure out how.

1条回答
家丑人穷心不美
2楼-- · 2019-04-13 18:50

You can get chart as image and embed it to message

Simple example

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,
    }
  });
}

I hope it helps =)

查看更多
登录 后发表回答