Insert images on Google Sheet

Hi everyone!
I have a workflow where I’m attempting to insert images into Google Sheet cells using the Google Sheets Module or even via an API request, but I haven’t found any way to update cells by directly inserting images, without using the IMAGE FORMULA.

I can’t use the =IMAGE(“”) formula because when downloading the .xlsx file, it requests image permissions in Excel for each row, and having more than 10 rows makes this impractical.

I’ve tried numerous workarounds, including using Excel Online instead of Google Sheets. However, I haven’t found a way to programmatically INSERT images into cells that would solve my issue at its core.

If anyone knows how to do this or has another workaround to suggest, I would greatly appreciate it.
Thank you.

All the known methods are listed in this blog post How to Insert Images in Google Sheet Cells - Digital Inspiration

2 Likes

Thank you Sam, I’ve made a workaround using App Script and custom coding based on this article.

Thanks again !

2 Likes

Hi Juani. I have been trying to get this done by code in apps script. But i am not able to insert the image inside the cell. Just have it floating over the cell. Can you send me your code or help me with this? Thank you so much!

Hi, sorry for the late reply. The script that I used retrieves the URL from a cell and converts it into an image.

This is what I did:

const useCellImageBuilder = () => {
  try {
    const sheet = SpreadsheetApp.getActiveSheet();
    const lastRow = sheet.getLastRow();
    
    for (let i = 1; i <= lastRow; i++) {
      const imageUrl = sheet.getRange('M' + i).getValue();
      
      if (imageUrl !== '') {
        const imageDescription = 'Image';
        const cellImage = SpreadsheetApp.newCellImage()
          .setSourceUrl(imageUrl)
          .setAltTextTitle(imageDescription)
          .build()
          .toBuilder();
        
        const cell = sheet.getRange('A' + i);
        cell.setValue(cellImage);

          sheet.getRange('M' + i).clearContent();
      }
    }
  } catch (f) {
    Browser.msgBox(f.message);
  }
};

Hope it helps.

2 Likes

Thank you so much, Juani!!