Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting images in Google sheet via script error

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".

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);

Unrelated topic, where do I get the documentation for sheet.getImages() because I just couldn't find it here

like image 291
Tam Le Avatar asked Oct 02 '18 04:10

Tam Le


1 Answers

  • You want to delete the image on Spreadsheet using Google Apps Script.

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?

Sample script:

var images = sheet.getImages();
var img = images[0];
img["delete"](); // this one

Note:

  • 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.

If I misunderstand your question, I'm sorry.

Update at 2018 October 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

Update at 2018 October 31:

This was officially released at October 30, 2018.

You can see the document at Class OverGridImage.

like image 135
Tanaike Avatar answered Oct 26 '22 22:10

Tanaike