0

I want to show an image from Google Drive in a Google Spreadsheet. I have to replace the text: open? for: uc?export=download& in the Shareable link: https://drive.google.com/open?id=0BwJUnx7uETDmaG42eGdEVUVocU0

I have tried this solution https://stackoverflow.com/a/42819032/2661411:

" I made a two lines script to use the share link of an image in Google Drive.

  1. Go to Tools > Script editor.
  2. Copy, paste the following code
  3. Click on run for permission

    function DRIVE_IMAGE(link){ prefix_url = "https://docs.google.com/uc?export=download&"; link.replace("open?", "uc?export=download&"); }

Using the script :

  1. Copy the share link of your image in Google Drive.
  2. Go to a cell
  3. Enter the formula =IMAGE(DRIVE_IMAGE("COPIED_LINK")) "

But didn't work for me, it said:

TypeError: Cannot call method "replace" of undefined. (line 3, file "ImgView")

Any ideas? I would like it to keep it simple.

isk27
  • 329
  • 2
  • 5
  • 13

1 Answers1

2

You need to use https://docs.google.com/uc?export=download&id=<<IMAGE ID>>. Refer the below formula.

=image("https://docs.google.com/uc?export=download&id=0BwJUnx7uETDmaG42eGdEVUVocU0")

Script

/**
 * @customfunction
 */
function DRIVE_IMAGE(link){
   var newLink = link.replace("https://drive.google.com/open?", "https://docs.google.com/uc?export=download&");
   return newLink;
}

Now, you can use the formula =IMAGE(DRIVE_IMAGE("https://drive.google.com/open?id=0BwJUnx7uETDmaG42eGdEVUVocU0"))

Ritesh Nair
  • 3,327
  • 1
  • 17
  • 24
  • That is what I'm trying to do... but how? (I need a script) – isk27 Jul 28 '17 at 19:00
  • @isk27 I have added the script – Ritesh Nair Jul 28 '17 at 19:13
  • Is there any way to make a range selection? for example, I got a column with all the links to the images in the Drive and in the next column the formula that gets the correct link from the other column in the same row? – isk27 Jul 28 '17 at 21:07