I have an image in a folder that I want to import into my spreadsheet (in a cell). I'm using the script from Insert image from Google Drive into Google Sheets (with some modifications).
But this only works on one of the images.
I could see that the other image is a .png and the first image was a .jpg. I tried to convert the .png into .jpg, but it still does not work.
The modified script:
function listFilesInFolder(folderName) {
//writes the headers for the spreadsheet
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow(["Image"]);
var folderId = "1smphWTohvgOVTwGDbxrIxsFWeFd3tBNo";
var folder = DriveApp.getFolderById(folderId);
var contents = folder.getFiles();
var cnt = 0;
var file;
while (contents.hasNext()) {
var file = contents.next();
cnt++;
Logger.log(file);
Logger.log(cnt);
// writes the various chunks to the spreadsheet- just delete anything you don't want
data = [
"https://docs.google.com/uc?export=download&confirm=no_antivirus&id=" + file.getId(),
file.getDescription(),
"=image(\"https://docs.google.com/uc?export=download&id=" + file.getId() +"\")",
];
sheet.appendRow(data);
};
};