我正在使用以下内容遍历工作表名称“图表”上的所有图表,并将它们作为嵌入式图像附加。
在htmlBody中,我在需要的地方将每个图表作为字符串ChartXString引用。
var Chart1Sheet = SpreadsheetApp.getActive().getSheetByName('Charts');
var charts1 = Chart1Sheet.getCharts();
var chartBlobs1=new Array(charts1.length);
var emailImages1={};
for(var i=0;i<charts1.length;i++){
var builder = charts1[i].modify();
builder.setOption('vAxis.format', '#');
var newchart = builder.build();
chartBlobs1[i]= newchart.getAs('image/png');
chart1String = "<p align='center'><img src='cid:chart"+0+"'></p>";
chart2String = "<p align='center'><img src='cid:chart"+1+"'></p>";
chart3String = "<p align='center'><img src='cid:chart"+2+"'></p>";
chart4String = "<p align='center'><img src='cid:chart"+3+"'></p>";
emailImages1["chart"+i]= chartBlobs1[i];
}
myHTML = myHTML + myHTML2 + myHTML3 + myHTML4 + myHTML5 + chart1String + chart2String + chart3String + chart4String + myHTML6;
recipient = 'email@address';
subject = 'My subject text';
body = 0;
MailApp.sendEmail(recipient, subject, body, {htmlBody: myHTML, inlineImages:emailImages1});
这工作得很好,但是我想添加一个像the example from the documentation这样的图像。
var youtubeLogoUrl =
"https://developers.google.com/youtube/images/YouTube_logo_standard_white.png";
var youtubeLogoBlob = UrlFetchApp
.fetch(youtubeLogoUrl)
.getBlob()
.setName("youtubeLogoBlob");
MailApp.sendEmail({
to: "recipient@example.com",
subject: "Logos",
htmlBody: "inline YouTube Logo <img src='cid:youtubeLogo'>",
inlineImages:
{
youtubeLogo: youtubeLogoBlob
}
});
我认为问题不在于如何添加对象。到目前为止,这是我尝试过的:
var youtubeLogoUrl =
"https://developers.google.com/youtube/images/YouTube_logo_standard_white.png";
var youtubeLogoBlob = UrlFetchApp
.fetch(youtubeLogoUrl)
.getBlob()
.setName("youtubeLogoBlob");
LogoStr = "<img src='cid:youtubeLogo'>";
var Chart1Sheet = SpreadsheetApp.getActive().getSheetByName('Charts');
................
chart4String = "<p align='center'><img src='cid:chart"+3+"'></p>";
emailImages1["chart"+i]= chartBlobs1[i] + youtubeLogoBlob;
}
myHTML = LogoStr + myHTML + myHTML2 + myHTML3 + myHTML4 + myHTML5 + chart1String + chart2String + chart3String + chart4String + myHTML6;
recipient = 'email@address';
subject = 'My subject text';
body = 0;
MailApp.sendEmail(recipient, subject, body, {htmlBody: myHTML, inlineImages:emailImages1});
我也尝试过:
MailApp.sendEmail(recipient, subject, body, {htmlBody: myHTML, inlineImages:emailImages1,youtubeLogoBlob});
答案 0 :(得分:1)
youtubeLogoBlob
中的emailImages1
作为inlineImages。如果我的理解是正确的,那么该修改如何?请按如下所示修改问题中的第三个脚本。
emailImages1["chart"+i]= chartBlobs1[i] + youtubeLogoBlob;
}
myHTML = LogoStr + myHTML + myHTML2 + myHTML3 + myHTML4 + myHTML5 + chart1String + chart2String + chart3String + chart4String + myHTML6;
recipient = 'email@address';
subject = 'My subject text';
body = 0;
MailApp.sendEmail(recipient, subject, body, {htmlBody: myHTML, inlineImages:emailImages1});
emailImages1["chart"+i]= chartBlobs1[i]; // Modified
}
emailImages1["youtubeLogo"] = youtubeLogoBlob; // Added
myHTML = myHTML + myHTML2 + myHTML3 + myHTML4 + myHTML5 + chart1String + chart2String + chart3String + chart4String + myHTML6;
recipient = 'email@address';
subject = 'My subject text';
body = 0;
MailApp.sendEmail(recipient, subject, body, {htmlBody: myHTML, inlineImages:emailImages1}); // Modified
如果我误解了你的问题,我表示歉意。