发送电子邮件时如何在工作表中添加现有图表

时间:2019-06-17 09:17:04

标签: google-apps-script

我希望电子表格中的折线图显示在电子邮件中。

a - atan()  - -0.0003351970075579
a - atan2() - -0.0003351970075579
b - asin()  - 0.0000856336001047
m6 - got      [ -0.0000856336000000 ]
m6 - expected [ -0.0000856336000000 ]

m7 - got      [ -0.0003351970000519 ]
m7 - expected [ -0.0003351970000000 ]

m8 - got      [ 0.9999999401549271 ]
m8 - expected [ 0.9999999400000000 ]

当我尝试将图表添加到第7行的变量#include <stdio.h> #include <math.h> int main() { /* m6 = -sin b*/ double m6 = -0.0000856336; /* m7 = sin a * cos b */ double m7 = -0.0003351970000000; /* m8 = cos a * cos b */ double m8 = 0.9999999400000000; /* a = atan(m7 / m8) = atan2(m7,m8)*/ double a1 = atan(m7 / m8); double a2 = atan2(m7 , m8); double b = -asin(m6); printf("a - atan() - %.16f\n", a1); printf("a - atan2() - %.16f\n", a2); printf("b - asin() - %.16f\n", b); /* Inverse transformation */ double m6p = -sin(b); double m7p = sin(a2) * cos(b); double m8p = cos(a2) * cos(b); printf("m6 - got [ %.16f ]\n", m6p); printf("m6 - expected [ %.16f ]\n\n", m6); printf("m7 - got [ %.16f ]\n", m7p); printf("m7 - expected [ %.16f ]\n\n", m7); printf("m8 - got [ %.16f ]\n", m8p); printf("m8 - expected [ %.16f ]\n", m8); return 1; } 时,它将引发异常。

1 个答案:

答案 0 :(得分:0)

如果我的理解正确,那么您已经在电子表格中创建了没有问题的图表,并且只想将其作为图像来获取。为此,您需要引用工作表中的图表,然后在图表的Blob上使用getAs()方法,对您来说,它看起来像这样:

var chart = sheet.getCharts()[0]; // assuming you only have that chart, this is just to get the chart's reference.
var options = {
    htmlBody: "<img src='cid:chart' style='width:24px; height:16px;'/>",
    noReply:true
};

var chartImg = chart.getBlob().getAs('image/png').setName("areaBlob");

// Then you would add it in the body of the email as an attachment
MailApp.sendEmail({
    to: "xxx@der.com",
    subject: subject,
    htmlBody: options,
    inlineImages: {
        chart: chartImg,
    }
});

在下面的链接中,您可以找到更深入的说明和示例:Chart image in email from Google spreadsheet with google-apps-script returns white image