Google Script: how to send Tablechart in e-mail?

会有一股神秘感。 提交于 2021-02-10 15:00:29

问题


I'm creating a tablechart in Google Script and I want to send this through e-mail.

This is my code

var data = Charts.newDataTable()
      .addColumn(Charts.ColumnType.STRING, 'Month')
      .addColumn(Charts.ColumnType.NUMBER, 'In Store')
      .addColumn(Charts.ColumnType.NUMBER, 'Online')
      .addRow(['January', 10, 1])
      .addRow(['February', 12, 1])
      .addRow(['March', 20, 2])
      .addRow(['April', 25, 3])
      .addRow(['May', 30, 4])
      .build();

  var chart = Charts.newTableChart()
      .setDataTable(data)
      .enableSorting(true)
      .build();

  MailApp.sendEmail({
    to: "me@gmail.com",
    subject: "Test",
    htmlBody: "inline Google Logo<img src='cid:inImage'> images! <br>",
    inlineImages:
      {
        inImage: chart.getBlob().setContentType('image/png'),
      }
  });

The code gives the following error message on chart.getBlob().setContentType('image/png'):

"We're sorry, a server error occurred. Please wait a bit and try again".

Anyone any idea what's wrong?

Thanks!


回答1:


How about this modification?

From:

var chart = Charts.newTableChart()
    .setDataTable(data)
    .enableSorting(true)
    .build();

To:

var chart = Charts.newTableChart()
    .setDataTable(data)
    .enableSorting(true)
    .setDimensions(640, 480) // Added
    .build();

It sets the size of chart using setDimensions().

Note:

  • Also you can use chart.getAs('image/png') instead of chart.getBlob().setContentType('image/png').

Reference:

  • setDimensions(width, height)

If this was not what you want, please tell me. I would like to modify it.



来源:https://stackoverflow.com/questions/52919710/google-script-how-to-send-tablechart-in-e-mail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!