来自谷歌电子表格的电子邮件中的图表图像与谷歌应用程序脚本返回白色图像 [英] Chart image in email from Google spreadsheet with google-apps-script returns white image

查看:147
本文介绍了来自谷歌电子表格的电子邮件中的图表图像与谷歌应用程序脚本返回白色图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每晚都会发送一份报告给我自己的Gmail地址。突然一周左右,图表的图像变成了空白。只有一个图表。

  function sendReport(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(monthData);
var charts = sheet.getCharts();

if(charts.length> 0){
var template = HtmlService.createTemplateFromFile(reportTemplate);
template.date = Utilities.formatDate(new Date(),Session.getScriptTimeZone(),dd-MM-y);
var areaBlob = charts [0] .getBlob()。getAs('image / png')。setName(areaBlob);
MailApp.sendEmail({to:olivier.dejonge@gmail.com,
主题:Trend uren declarabel,
htmlBody:template.evaluate()。getContent(),
inlineImages:{
图表:areaBlob
}
});
} else {
Browser.msgBox(Kon report niet verzenden omdat ik chart niet kon vinden);


code $

$ b

Code.gs

 < html> 
< h1> Dagelijkse趋势声明:<?= date?>< / h1>
< p>
< img src =cid:chart/>
< / p>
< / html>

reportTemplate.html



电子表格中的

看起来很好



在电子邮件中不存在!?



更新



当我使用电子表格的函数updateUren更新数据时,图表也保持空白。

  function updateUren()
{
var activeSpreadSheet = SpreadsheetApp.getActiveSpreadsheet();
var startYear = activeSpreadSheet.getSheetByName(settings)。getRange(2,1,1,1).getValue();
var endYear = activeSpreadSheet.getSheetByName(settings)。getRange(2,2,1,1).getValue();
var calendars = activeSpreadSheet.getSheetByName(settings)。getRange(2,3,1,1).getValue()。split(/);
var hourPriceArr = activeSpreadSheet.getSheetByName(settings)。getRange(2,4,1,1).getValue()。split(/);
var myPrice = hourPriceArr [0] .split(,);
var myHourPrice = [];
for(var i = 0; i< myPrice.length; i ++){
var orgPrice = myPrice [i] .split(:);
myHourPrice.push(orgPrice)
}
var vasilesPrice = hourPriceArr [1] .split(,);
var vasileHourPrice = [];
for(var i = 0; i< vasilesPrice.length; i ++){
vasileHourPrice.push(vasilesPrice [i] .split(:))
}
var hourHash = [{hourPrice:myHourPrice,hirePrice:[]},{hourPrice:myHourPrice,hirePrice:vasileHourPrice}]

var startDate = new Date();
var details = [];

for(var i in calendar)
{
startDate = collectEvents_(details,calendar [i],startYear,endYear,startDate,hourHash [i] .hourPrice,hourHash [ I] .hirePrice);
}

/ * month * /
var monthDetails = getMonthDetails_(details);

sheet = activeSpreadSheet.getSheetByName(monthData);
var range = sheet.getRange(A2:E)
range.clear();
sheet.getRange(2,1,monthDetails.length,5).setValues(monthDetails);

$ b $ *全部* /
details.unshift([title,date,start,end,duration,profit]] );
sheet = activeSpreadSheet.getSheetByName(data);
sheet.clear();
sheet.getRange(2,1,details.length,6).setValues(details);
}

只有在浏览器中刷新页面时,图表才会显示它的图形再次。

解决方案

空白图片归结于共享权限问题。将电子表格的共享设置更改为任何拥有链接的人都可以查看,然后可以从脚本导出图表。


I'm sending a report every night to my own gmail address. Suddenly since a week or so the image of the chart has turned blank. There is only one chart.

function sendReport() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("monthData");
  var charts = sheet.getCharts();

  if(charts.length > 0) {
    var template = HtmlService.createTemplateFromFile("reportTemplate");
    template.date = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "dd-MM-y");
    var areaBlob = charts[0].getBlob().getAs('image/png').setName("areaBlob");
    MailApp.sendEmail({ to:"olivier.dejonge@gmail.com",
                        subject: "Trend uren declarabel",
                        htmlBody: template.evaluate().getContent(),
                        inlineImages: {
                          chart: areaBlob
                        }
                      });
  }else {
    Browser.msgBox("Kon report niet verzenden omdat ik chart niet kon vinden");
  }
}

Code.gs

<html>
  <h1>Dagelijkse Trend Declarabele uren: <?= date ?></h1>
  <p>
    <img src="cid:chart" />
  </p>
</html>

reportTemplate.html

in spreadsheet it looks fine

in email it's not there!?

Update

When I update the data with function "updateUren" of the spreadsheet the chart stays blank too.

function updateUren()
{
  var activeSpreadSheet = SpreadsheetApp.getActiveSpreadsheet();
  var startYear = activeSpreadSheet.getSheetByName("settings").getRange(2,1,1,1).getValue();
  var endYear = activeSpreadSheet.getSheetByName("settings").getRange(2,2,1,1).getValue();
  var calendars = activeSpreadSheet.getSheetByName("settings").getRange(2,3,1,1).getValue().split("/");
  var hourPriceArr = activeSpreadSheet.getSheetByName("settings").getRange(2,4,1,1).getValue().split("/");
  var myPrice = hourPriceArr[0].split(",");
  var myHourPrice = [];
  for(var i=0 ; i < myPrice.length; i++) {
    var orgPrice = myPrice[i].split(":");
    myHourPrice.push(orgPrice)
  }
  var vasilesPrice = hourPriceArr[1].split(",");
  var vasileHourPrice = [];
  for(var i=0 ; i < vasilesPrice.length ; i++) {
    vasileHourPrice.push(vasilesPrice[i].split(":"))
  }
  var hourHash = [{hourPrice:myHourPrice, hirePrice:[]}, {hourPrice:myHourPrice, hirePrice:vasileHourPrice}]

  var startDate = new Date();
  var details=[]; 

  for(var i in calendars)
  {
    startDate = collectEvents_(details, calendars[i], startYear, endYear, startDate, hourHash[i].hourPrice, hourHash[i].hirePrice);
  }

  /*month*/
  var monthDetails = getMonthDetails_(details); 

  sheet = activeSpreadSheet.getSheetByName("monthData");
  var range = sheet.getRange("A2:E")
  range.clear();
  sheet.getRange(2, 1, monthDetails.length, 5).setValues(monthDetails);


  /*all*/
  details.unshift(["title", "date", "start", "end", "duration", "profit"]);
  sheet = activeSpreadSheet.getSheetByName("data");
  sheet.clear();
  sheet.getRange(2, 1, details.length, 6).setValues(details);
}

It's only when I refresh the page in the browser that the chart shows it's graph again.

解决方案

The blank image is due to a sharing permissions issue. Change the share settings of the spreadsheet to "Anyone who has the link can view" and the chart will then be exportable from your script.

这篇关于来自谷歌电子表格的电子邮件中的图表图像与谷歌应用程序脚本返回白色图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆