- You want to send email including the 3D chart on Spreadsheet.
If my understanding is correct, how about this workaround? I experienced the same issue with you. When the chart on Spreadsheet are retrieved as a blob, the chart of the blob is different from the original chart. I think that this might be a bug. In this case, as one of several workarounds, I used the following flow.
Flow of modified script:
- Retrieve charts from Spreadsheet.
- Create Google Slides as a temporal.
- Insert the charts to Slides as images.
- Retrieve the inserted charts as blobs.
- Send email including the retrieved blob.
- Remove the temporal Google Slides.
Modified script:
In this modification, I modified your script. Please modify your script as follows.
function email(sheet, toMail, ccMail, msg){
var charts = sheet.getCharts();
var slides = SlidesApp.create("sample"); // Added
var slide = slides.getSlides()[0]; // Added
var emailImages={};
var chartBlobs=new Array(charts.length);
var emailBody = ""; // Added
for(var i=0;i<charts.length;i++){
var image = slide.insertSheetsChartAsImage(charts[i]); // Added
chartBlobs[i]= image.getAs("image/png").setName("chartBlob"+i); // Modified
emailBody= emailBody + "<p align='left'><img src='cid:chart"+i+"'></p>";
emailImages["chart"+i]= chartBlobs[i];
}
MailApp.sendEmail({
to: toMail,
cc: ccMail,
subject: "ABC",
htmlBody: emailBody,
inlineImages:emailImages});
DriveApp.getFileById(slides.getId()).setTrashed(true); // Added
}
Note:
- In this modified script, the temporal Google Slides is moved to the trash box.
- I reported this issue to the issue tracker.
References:
If I misunderstood your question and this workaround was not what you want, I apologize.