通过脚本错误删除Google工作表中的图像 [英] Deleting images in Google sheet via script error
问题描述
我可能会为此而感到沮丧,但我无能为力.我搜索,阅读并尝试了很多东西.我在Javascript和Google平台上都是新手.
I probably will get downvoted for this but I can't do anything else. I searched, read and tried SOOOO many things. I am new at both Javascript and Google platform.
我有一段不断告诉我的代码
I have this piece of code that keeps telling me
.操作后缺少名称".
"Missing name after . operation".
即使.delete
和.getAltTextTitle
都显示在自动填充建议中
Even though .delete
and .getAltTextTitle
are both shown in autocomplete suggestion
var images = sheet.getImages();
var img = images[0];
Logger.log(img.getAltTextTitle()); //This is fine
img.delete(); //This throw error
同时,我的这段代码工作得很好.我不知道该怎么办.它们对我来说看起来一样.
In the meanwhile, I have this piece of code working totally fine. I don't know what to do. They look the same to me.
var img = sheet.getImages()[0];
var imgH = img.getHeight();
var imgW = img.getWidth();
var maxW = 700;
var newImgH = Math.round(imgH*(maxW/imgW));
img.setWidth(maxW);
img.setHeight(newImgH);
不相关的主题,在哪里可以找到sheet.getImages()
的文档,因为我只是找不到它此处
Unrelated topic, where do I get the documentation for sheet.getImages()
because I just couldn't find it here
推荐答案
- 您要使用Google Apps脚本删除电子表格上的图像.
如果我的理解是正确的,我认为delete()
可能是新方法,将在不久的将来为电子表格添加.因此,该文档尚未更新,因此可能尚未完成.但是从错误消息中,如果您想使用当前的delete()
方法,该示例脚本如何?
If my understand is correct, I think that delete()
might be new method which will be added for Spreadsheet in the near future. So the document is not updated and it might not complete yet. But from the error message, if you want to use the current delete()
method, how about this sample script?
var images = sheet.getImages();
var img = images[0];
img["delete"](); // this one
注意:
- 我认为详细信息可以添加到此文档.
- 在我的环境中,我可以确认可以通过
img["delete"]()
删除图像.我认为这是一种新方法. - I think that the detail infomation might be added to this document.
- In my environment, I could confirm that the image can be deleted by
img["delete"]()
. I think that this is one of new methods.
Note:
如果我误解了你的问题,对不起.
If I misunderstand your question, I'm sorry.
现在为了删除图像,可以使用以下方法.这已在2018年10月13日得到确认.
Now in order to delete the image, the following method can be used. This was confirmed at 2018 October 13.
var images = sheet.getImages();
var img = images[0];
img.remove(); // Here
于2018年10月31日更新:
您可以在 Class OverGridImage .
这篇关于通过脚本错误删除Google工作表中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!