As @nguyen-hieu suggested, for what you want to do in the spreadsheet you are showing, his/her answer is a good solution
=image("https://drive.google.com/uc?export=download&id="&right(A2;33);1).
More Advanced Option
When you want to query an image based on a constantly changing cell content, like a data validation dropdown menu list, use this code
=IMAGE( CONCATENATE("https://drive.google.com/uc?export=download&id=", QUERY(Images, "SELECT B WHERE A = '" & Item & "'", 0)) , 1)
Dissection of the Formulas
Sheet: Images
In this sheet you want to keep all your images (best if you only use the URL ID
)
| A | B |
--------------
|Item |ImageID|
--------------
|Hammers |XYZABC |
--------------
|Chairs |ABCXYZ |
--------------
|Wood |ABXXYA |
Main Sheet
Let's say you have a main sheet (ej. Summary
) with a drop down menu (data validation list
) in $A$2
of the full list of items from the sheet =Images!$A:$A
- To make coding much easier, create the following
Named Ranges
:
- Item:
=Summary!$A$2
- Items: (
=Images!$A:$B
)
- On the cell you to display to display the image use this code
=IMAGE( CONCAT("https://drive.google.com/uc?export=download&id=", QUERY(Images, "SELECT B WHERE A = '" & Item & "'", 0)) , 1)
=Image
The formula Image needs a URL and the format needs to be "https://drive.google.com/uc?export=download&id=GoogleDriveImageID
The number 1 specifies the image to auto-resize to take the whole width of the cell. Keeping the aspect ratio. If you want to use the height of the row instead, replace it for the number 2
=CONCAT
- To give the formula
=IMAGE
a URL that it can use, CONCAT
puts together the string "https://drive.google.com/uc?export=download&id=
and the image ID from the sheet Images.
As an alrernative, you can add this CONCAT
formula in your Images
sheet, on Column C, CONCAT( "https://drive.google.com/uc?export=download&id=", $B:$RowNumber )
for every entry (replace RowNumber
for the actual row number of the entry) and then update your IMAGE
formula to this:
=IMAGE( QUERY(Images, "SELECT C WHERE A = '" & Item & "'", 0)) , 1)
Removing CONCAT
and replacing the column B
for the column C
in the SELECT statement. ALSO update the named range Images
to Images!A:C
=QUERY
This function is the "workhorse of the show". QUERY
will get the image ID based on the value of the cell (in this example, Summary!$A:$2
or Image
named range).
QUERY(Images, "SELECT B WHERE A = '" & Item & "'", 0)
The named range Images
replaces Images!$A:$B
, and gives you the data you need based on the query "SELECT B WHERE A = 'Item'"
The Item
portion of the WHERE query is the named range Item
(Summary!$A:$2
).
Finally, the number 0 after the comma, at the end of the select query statement QUERY(Images, "SELECT B WHERE A = '" & Item & "'"
, 0)
is required to remove the headers from the first row (Images!$A$1
; |Item |ImageID|
)