下面的新问题出现在Google-Docs附加脚本中,我相信没有更改脚本或源文档。
从今天下午开始,以下代码开始在line处挂起:var blob = sourceImage.asInlineImage().getBlob()。记录器正确地记录了图像的宽度和高度,但从不记录“blobbed”。
var sourceImage = cell.getChild(m).getChild(0);
var imageHeight = sourceImage.getHeight();
var imageWidth = sourceImage.getWidth();
Logger.log('imageWidth:' + imageWidth + ', imageHeight:' + imageHeight);
var blob = sourceImage.asInlineImage().getBlob();
Logger.log('blobbed');我试着用一个新的图像完全替换源图像,没有调整大小,没有裁剪。这导致了日志中正确的新宽度和高度输出,但是代码再一次没有通过getBlob()行,没有异常被记录(堆栈驱动错误报告和堆栈驱动日志记录都是空的)。同样的问题也会发生在其他源文档上。
源文档位于共享驱动器中。直到大约一周前,这个脚本还在运行。和权限有什么关系?API中有什么变化吗?你知道是什么原因造成的吗?
发布于 2019-09-20 09:40:45
在准备一个最小的完整可验证示例时,我发现问题出在element.copy()中。脚本将元素从一个页面复制到另一个页面。代码首先执行复制,然后遍历复制的子对象。显然,element.copy()复制了所有子项,但如果其中一个子项包含图像,则不能对复制的图像使用getBlob()。
而不是:
var element = templateBody.getChild(i).copy();
...
newParagraph = target.appendParagraph(element)
...
newTable = body.appendTable(element);使用:
var element = templateBody.getChild(i);
...
newParagraph = target.appendParagraph(element.copy())
...
newTable = body.appendTable(element.copy());不使用element.copy(),现在可以对类型为table的元素的子元素使用getBlob():
element.getChild(j).getCell(k).getChild(m).getChild(0).asInlineImage().getBlob();直到上周左右,仍不清楚为什么旧版本的代码可以正常工作。
https://stackoverflow.com/questions/58019879
复制相似问题