5

I would like to remove/delete an image that I inserted into a google sheet. I used the code:

sheet.insertImage(url,col,row);

to insert the image. But, I want to remove the image later in the code and insert a different image. or not have an image at all.

user3158459
  • 61
  • 1
  • 4

3 Answers3

7

Try the following:

      // Deletes all images in sheet
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getSheetByName("Your Tab Name");
      var images = sheet.getImages();
      images.map(function(img){img.remove();});
Sherm4n
  • 332
  • 5
  • 7
-1

use this code to remove your image

    function clearRange() {
  //replace 'Sheet1' with your actual sheet name
  var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
  sheet.getRange('B7:G7').clearContent();
}
Hamelraj
  • 4,676
  • 4
  • 19
  • 42
-1

In my testing, inserting a different image, in the the same cell, simply stacks the new image over the top of the old image.

sheet.insertImage('http://somewhere.com/images/image1.png',col,row);
sheet.insertImage('http://somewhere.com/images/image2.png',col,row);

I had hoped to effectively 'remove' image1 by substituting a blank(transparent) image2. One can cover up image1 with some other opaque image. ('mask', 'overlay', 'overlap' 'conceal', 'hide')

overlapped images In my experience, theCell.clearContent() does not affect the image but will clear other cell contents.

oakie22
  • 21
  • 5