This is a sample script for retrieving images on Spreadsheet.
Unfortunately, there are no methods for retrieving directly images on spreadsheet using GAS. So I use the method which retrieves URL from =image(URL) and retrieves the image from the URL.
In this case, =image(URL) has to be in the cell. Images embedded by insertImage() cannot be retrieved.
At first, please confirm them.
Sample script :
var cell = "A1"; // Cell address with the function of "=image()"
var filename = "samplename"; // Output filename
var image = SpreadsheetApp.getActiveSheet().getRange(cell).getFormula();
var blob = UrlFetchApp.fetch(image.match(/\"(.+)\"/)[1]).getBlob();
DriveApp.createFile(blob.setName(filename));
Flow :
- Retrieve =image(URL)usinggetFormula().
- Retrieve URL from =image(URL).
- Retrieve file blob using UrlFetchApp.fetch()from the URL.
- Output the file blob as a file.