How to add inline diagram extracted from spreadsheet to email?

Purpose: to take the existing chart from the Google spreadsheet, add the built-in email, and send. I believe that the GetChart class can help, but cannot figure out how to do this.

+2
source share
1 answer

You can get the chart as an image and embed it in the 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 this helps =)

+4
source

All Articles