I am currently inserting multiple images in a Google Sheets via AppsScript function InsertImage
With it the function inserts the image but above the cell (not inside the
There is currently no method in apps script to insert a image in cell. There is a open feature request here. Consider adding a star(on top left) to it for Google to prioritize the issue.
Here we use =IMAGE()
formula to insert a image and copy paste values only to get the raw image. This is mentioned by me here and in comment#65 of the issuetracker.
const insertInCellImage_ = (url, rg) => {
rg.setValue(`=IMAGE("${url}")`);
SpreadsheetApp.flush();
rg.copyTo(rg, { contentsOnly: true });
};
/*Inserts Google logo in Sheet1!A1*/
const test1 = () =>
insertInCellImage_(
'https://www.google.com/images/srpr/logo3w.png',
SpreadsheetApp.getActive()
.getSheetByName('Sheet1')
.getRange(1, 1)
);