3

I have a Google Spreadsheet with an image that has been inserted into a cell. I need to access the URL of this image from Google Apps Script. The documentation only seems to cover OverGridImage which are images that can be moved around. My image has been inserted into a cell.

I have tried this code, but it doesn't return images that have been inserted into a cell.

var images = sheet.getImages();

for (var i = 0; i < images.length; i++) {
  Logger.log(images[i].getAnchorCell().getRow());
}

The Range class has some methods for getting the background, but this is for colour, not images.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Robbie Lewis
  • 2,844
  • 3
  • 18
  • 29
  • In order to correctly understand your situation, can you provide a sample Spreadsheet? – Tanaike Apr 04 '19 at 23:14
  • 1
    @Tanaike Thank you - https://docs.google.com/spreadsheets/d/12oysJsWS62Dw9ZLzZh7Fd-oYx-LYIoc-m3mUPUT7Wc4/edit?usp=sharing – Robbie Lewis Apr 11 '19 at 15:02
  • Thank you for sharing it. I check it. But it seems that the image doesn't have the URL. Can I ask you about the method for putting this image? I thought that from the method, the workaround might be able to be thought. – Tanaike Apr 11 '19 at 22:24
  • @Tanaike In the google sheet, go to Insert > Image > Image In Cell – Robbie Lewis Apr 15 '19 at 10:33
  • 1
    Thank you for replying. Unfortunately, in the current stage, the URL cannot be retrieved from the images putting with such method, yet. I apologize for this situation. – Tanaike Apr 15 '19 at 22:33
  • @Tanaike is this because Google has not updated the API? – Robbie Lewis Apr 16 '19 at 08:40
  • I apologize for my poor English skill. I thought that although the current API cannot achieve it yet, the possibility that it can achieve in the future cannot be denied. – Tanaike Apr 16 '19 at 11:51
  • 1
    @Tanaike Thank you, I understand what you are saying. – Robbie Lewis Apr 16 '19 at 13:47

1 Answers1

1

It's likely this (insert image INTO a cell) is too new and the API isn't ready. But, the alternative is to encode/decode the image in base64 and store them that way. That's what I'm doing now instead since I realized the insertImage method does what you just said. Insert images over the entire spreadsheet as opposed to the cell.

David Ho
  • 81
  • 7
  • Can I still display the image nicely in Google Sheets using this method? I want the end user to be able to see the image in the cell as it is displayed when using "Image in Cell" – Robbie Lewis Jun 11 '19 at 22:12
  • No, you'll just see a base64 string. Actually, I realize my method isn't the best. Each cell has a 50kb limit, and I'm resorting to LZW compression to get larger files in there. However, for my purposes, this is ok. But, I did come across this thread that you might find useful. The guy is inserting images from his Google Drive folder into the cell: https://stackoverflow.com/questions/26801041/what-is-the-right-way-to-put-a-drive-image-into-a-sheets-cell-programmatically – David Ho Jun 12 '19 at 04:22