Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Google Sheets Script to Remove Image Overlays

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To remove image overlays in Google Sheets via a script, you must use the OverGrid service to identify all Overlays of the type Image and call the remove() method on them. Because Google Sheets does not provide a built-in "Delete All Images" button for floating images (images inserted via Insert > Image > Insert over cells), a Google Apps Script is the only way to automate the cleanup of dozens or hundreds of overlapping graphics simultaneously. This process targets floating images specifically, not images embedded inside a cell using the =IMAGE() function.

What You'll Need

  • A Google account with access to the specific spreadsheet containing the images.
  • The spreadsheet must be open in a desktop web browser, as the Apps Script editor is not available on mobile apps.
  • Basic familiarity with copying and pasting text into a code editor.
  • Owner or Editor permissions for the sheet to authorize the script to modify the document.

Step-by-Step

  1. Open the Google Sheet that contains the image overlays you wish to remove.
  2. In the top menu bar, navigate to Extensions and then select Apps Script. This will open a new tab with the script editor. Note that menu labels may differ slightly depending on your region or account version.
  3. In the script editor, you will see a default function called myFunction(). Delete all the existing code in the editor window so that you have a completely blank slate.
  4. Copy and paste the following script into the editor:
    function removeAllImageOverlays() {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheets = ss.getSheets();
      
      sheets.forEach(function(sheet) {
        var images = sheet.getImages();
        images.forEach(function(image) {
          image.remove();
        });
      });
    }
      
  5. Click the Save icon (the floppy disk symbol) in the toolbar. Give your project a name, such as "Image Cleaner," and click OK.
  6. In the toolbar at the top of the editor, ensure that removeAllImageOverlays is selected in the dropdown menu next to the "Run" button.
  7. Click the Run button.
  8. Because this is the first time you are running the script, a dialog box titled "Authorization Required" will appear. Click Review Permissions.
  9. Select your Google account from the list.
  10. You may see a screen stating "Google hasn't verified this app." Since you are the author of this script for your own use, click Advanced and then click the link at the bottom that says Go to Image Cleaner (unsafe).
  11. On the final permission screen, click Allow to grant the script permission to access and modify your spreadsheets.
  12. The script will now execute. Once the "Execution log" at the bottom of the screen says "Completed," return to your Google Sheet tab. All floating image overlays across all tabs in that workbook should now be gone.

Common Mistakes

One of the most frequent mistakes is attempting to use this script to remove images that are embedded inside a cell. If you used the =IMAGE("url") formula or selected "Insert image in cell," this script will not work. Those images are treated as cell values or formatting, not as "Overlays." To remove those, you must select the cells and press the Delete key or clear the contents of the cells.

Another common error is failing to authorize the script correctly. Users often stop at the "Google hasn't verified this app" screen because it looks like a security warning. It is important to understand that this warning appears for any script you write yourself that hasn't been submitted to Google for a formal security review. As long as you wrote the code or trust the source, clicking "Advanced" is the standard way to proceed.

Some users try to run the script while the spreadsheet is in "View Only" mode. If you do not have Edit access to the file, the script will fail with a permissions error because it cannot modify the structure of the sheet to remove the images.

Tips

If you only want to remove images from a specific sheet rather than the entire workbook, you can modify the script. Instead of using ss.getSheets().forEach(...), you can use var sheet = ss.getSheetByName("Sheet1"); (replacing "Sheet1" with your actual tab name) and then call sheet.getImages().forEach(...). This prevents the accidental deletion of images on other tabs that you might want to keep.

To make this process easier to repeat in the future, you can add a custom menu button to your spreadsheet. By adding an onOpen() function to your script, you can create a menu item called "Tools" or "Clean Up" that allows you to run the image removal script without opening the Apps Script editor every time.

Before running a bulk deletion script, it is always a best practice to create a duplicate of your spreadsheet. Go to File > Make a copy. Since the image.remove() action is permanent and cannot be undone via the "Undo" (Ctrl+Z) button after the script has finished, having a backup ensures you don't lose important visual data accidentally.

Troubleshooting

If the script runs successfully but the images are still there, double-check that the images are actually "Overlays." Click on an image; if you cannot drag it around the screen freely, it is likely embedded in a cell and cannot be removed by the getImages() method. You will need to clear those cells manually.

If you encounter a "TypeError: Cannot read property 'remove' of undefined," it usually means the script is attempting to call a method on an object that doesn't exist. Ensure you are using the latest version of the Google Apps Script V8 engine, which is the default for all new projects. If you are working in a very old project, check the project settings to ensure the runtime is updated.

If the script hangs or takes a very long time to complete, it may be because you have thousands of images. Google Apps Script has a maximum execution time (usually 6 minutes for standard accounts). If you have an extreme number of images, you may need to run the script multiple times or process the sheets one by one by modifying the loop to target specific sheets.

If you receive a "Permission Denied" error even after authorizing, try refreshing the spreadsheet page. Sometimes the session token needs to be refreshed for the changes to take effect in the UI.

Frequently Asked Questions

Will this script delete images created with the =IMAGE formula?

No. The getImages() method only identifies images that are floating overlays. Images created via formulas are considered cell content and must be removed by deleting the formula in the cell.

Can I use this to remove only images of a certain size?

Yes, but it requires adding a conditional check. You would need to use image.getWidth() and image.getHeight() within the loop to check the dimensions before calling image.remove().

Does this script work on mobile devices?

The script can be executed if you have a custom menu set up, but you cannot write or edit the script using the Google Sheets mobile app. You must use a desktop browser to set up the script.

Is it possible to move images to a different sheet instead of deleting them?

Not easily. The Image class in Apps Script is limited. While you can remove them, there is no simple moveTo() method. You would have to capture the image properties and attempt to recreate it on another sheet, which is significantly more complex.

How do I stop the script from running on every single tab?

Replace the sheets.forEach block with a specific reference to one sheet using ss.getSheetByName("YourSheetName"). This tells the script to ignore all other tabs in the workbook.

Will this remove charts or drawings?

No. In Google Sheets, images, drawings, and charts are handled as different types of overlays. This specific script targets only the Image class. To remove drawings or charts, you would need to use different methods to identify those specific object types.