Update
Found an answer to what you actually wanted. There is IMAGE
(see reference), a function that adds an URL as an image into a cell (didn't know it existed). So you could do something like:
=IMAGE(GETCHARTURL(...))
Original workaround
You cannot add an image in a cell. You cannot show an image as the result of a formula either. The best What you can do is having a button that calls a Google Apps Script function that adds the images on top of the cells using Sheet.insertImage
(reference).
I've made this little script that automatically adds the image on top of the cells that have the value img+
followed by the image url (eg. img+https://example.com/image.png
):
const IMAGE_HEIGHT = 100 // Image height in pixels
function sameRange(a, b) {
return a.getGridId() === b.getGridId()
&& a.getA1Notation() === b.getA1Notation()
}
function addImages() {
const sheet = SpreadsheetApp.getActiveSpreadsheet()
const toChange = sheet
.createTextFinder(/^img\+https?:\/\//.source)
.useRegularExpression(true)
.findAll()
// Remove old image(s)
for (let img of sheet.getImages()) {
const range = img.getAnchorCell()
if (toChange.some(r => sameRange(r, range))) {
img.remove()
}
}
// Create new ones
for (let range of toChange) {
const url = range.getValue().toString().split(/\+(.*)$/, 2)[1]
const image = range.getSheet()
.insertImage(url, range.getColumn(), range.getRow(), 0, 0)
image.setAltTextTitle("Chart")
const w = image.getWidth()
const h = image.getHeight()
image.setWidth(IMAGE_HEIGHT*w/h) // Keep aspect ratio
image.setHeight(IMAGE_HEIGHT)
}
}
Then simply make a new button (a drawing with text) and set addImages
as the assigned script.
I don't know your exact use case so you will probably need to modify the script to better fit your needs.
References