return = Google Spreadsheet image

Viewed 32

I hope anyone could help me...

I tried to Put an Img as the return value of a function inside a Spreadsheet cell...

The input of the function is a string and because of this Keyword, I will show an image... Not the image string directly the image like I could do it with =IMAGE(URL)

function IconAuswahl(a){

 if (a === 'Test1') {
    result = (Image("https://i.imgur.com/Jm5ND1E.png" ));
  } else {
    result = 'NOT positive';
  }
}


function imgIn(){
let app = SpreadsheetApp;
let table = app.getActiveSpreadsheet();
let mySheet = table.getActiveSheet();
let cell = mySheet.getRange('A1');

cell.setValue('=Image("https://i.imgur.com/Jm5ND1E.png")') ;
}

With the last function, I'm able to put an image to any cell but I like to set this value inside the cell I call the function.

Thanks!

1 Answers

Custom functions resemble normal functions and changing the function itself is not possible. You can however return a url and try something like this:

=IFERROR(IMAGE(IconAuswahl(A1)),"Not Positive")

Where the custom function is:

function IconAuswahl(a){
 if (a === 'Test1') {
    return "https://i.imgur.com/Jm5ND1E.png";
  } else {
    throw new Error("")
  }
}
Related