Google Apps脚本无法从EmbeddedChartBuilder生成图像 [英] Google Apps Script fails to generate image from EmbeddedChartBuilder

查看:63
本文介绍了Google Apps脚本无法从EmbeddedChartBuilder生成图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有自定义脚本的Google Spreadsheet,已经运行了一年多,并且突然开始失败.

I have a Google Spreadsheet with a custom script that has been working just fine for more than a year and it suddenly started failing.

问题很容易重现,但是我不知道发生了什么. 我从电子表格内的单元格区域中创建了一个简单的图表:

The problem is very simple to reproduce, but I have no idea what's going on. I create a simple chart from a cell range inside my spreadsheet:

var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Sheet1");
var chart = sheet.newChart()
     .setChartType(Charts.ChartType.LINE)
     .addRange(sheet.getRange("A1:D4"))
     .setPosition(5, 5, 0, 0)
     .build();

我尝试从EmbeddedChart创建图像:

The I try to create an image from that EmbeddedChart:

sheet.insertImage(chart.getBlob(),6,1);

说不清

[服务错误:电子表格(xx行,文件))

[Service error: Spreadsheets (line xx, file "")]

很奇怪,我试图解决它,如果我将生成的图表插入工作表中,然后尝试从图表中创建图像,则它实际上可以工作:

Weird enough, I tried to work around it and if I insert the generated chart into the sheet and then try to create the image from the chart, it actually works:

   var temp = ss.insertSheet();
   temp.insertChart(chart);
   var charts = temp.getCharts();
   sheet.insertImage(charts[0].getBlob(),6,1);

我非常困惑,我不知道可能是什么问题. 问题是我有多个电子表格,其中的多个脚本运行了相同代码的某些变体,并且都因相同的错误而失败. 因此,将其中的每一个最后一个更改为使用临时表是一项艰巨的工作.

I'm extremely confused, I have no idea what could be the problem. The thing is I have multiple spreadsheets with multiple scripts running some variation of this same code and they are all failing with the same error. So changing every last one of them to use a temp sheet is a lot of work.

我已经在问题5549中创建了问题5549问题跟踪器,但没有人回复 所以我不知道该怎么办.

I've created issue 5549 in the issue tracker but nobody has replied so I don't know what to do.

有什么我想念的吗? 有人能弄清楚吗?

Is there something I'm missing? Can anybody figure this out?

推荐答案

这是由于电子表格中的错误所致-现在已修复.如果您避免尝试从图表中创建Blob,则暂时可以避免该问题.

This is due to a bug in Spreadsheets -- it's being fixed now. If you avoid attempting to create Blobs from charts, you'll avoid the issue for the time being.

这篇关于Google Apps脚本无法从EmbeddedChartBuilder生成图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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