0
votes

I have some data along with images in a Google Sheet. I am sending the data as a JSON response and I have deployed the script as a web app.

I am using the code:

SpreadsheetApp.openByID("<sheet_id>").getSheets[0].getDataRange().getValues()

I am able to load the data properly but I am not able to load the images. For the cells with image, I get Empty String.

Can you please suggest a way to load images using the same script?

If it can provide a URL to my image saved in the sheet, then also it will solve my problem as I just wan't to display the image.

1
When I load images to a webapp I use dataURIs. I normally build them before hand and store them in a file. But you can build them on the fly using a script like this: function convImageToURI(){ var file=DriveApp.getFileById("Image File Id") var blob=file.getBlob(); var b64Url='data:' + blob.getContentType() + ';base64,' + Utilities.base64Encode(blob.getBytes()); Logger.log(b64Url); return b64Url; } - Cooper

1 Answers

0
votes

At the moment, you can obtain the image URL but under very special conditions:

  1. The image has to be defined as an "Over cell" image (it cannot be an "In-cell image", as they are not supported by Apps Script).

  2. The images have to be inserted by URL (not by uploading it from your local system).

The way to do it would be to:

  1. Obtain the Sheet you want the images of.
  2. Obtain its images using the getImages() method.
  3. Obtain the URL of each image by using the getUrl() method.

If you are interested in the possibility of obtaining "in-cell" images more easily, I suggest you visit the feature requests in the Google's Public Issue Tracker or consider creating a brand new one.