简体   繁体   中英

How do you delete an image from a google sheet

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.

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM