Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Last active August 12, 2022 01:22
Show Gist options
  • Save tanaikech/d6594dc5c6c49a015c7d408c90e58bdc to your computer and use it in GitHub Desktop.
Save tanaikech/d6594dc5c6c49a015c7d408c90e58bdc to your computer and use it in GitHub Desktop.
Retrieving Images on Spreadsheet

Retrieving Images on Spreadsheet

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 :

  1. Retrieve =image(URL) using getFormula().
  2. Retrieve URL from =image(URL).
  3. Retrieve file blob using UrlFetchApp.fetch() from the URL.
  4. Output the file blob as a file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment