Skip to content

Instantly share code, notes, and snippets.

@jonathanzuniga
Forked from palumbo/Download Images.gs
Created July 14, 2023 19:36
Show Gist options
  • Select an option

  • Save jonathanzuniga/589d533e35473f37a37e702d16530a81 to your computer and use it in GitHub Desktop.

Select an option

Save jonathanzuniga/589d533e35473f37a37e702d16530a81 to your computer and use it in GitHub Desktop.
The code I used to download images into a Google Sheets cell or download images into a Google Drive folder.
function insertImage() {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let lastRow = sheet.getLastRow();
for (let i = 0; i < lastRow-1; i++) {
let url = sheet.getRange(2+i,1).getValue();
let image = SpreadsheetApp.newCellImage().setSourceUrl(url);
sheet.getRange(2+i,2).setValue(image);
}
}
function downloadImage() {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let lastRow = sheet.getLastRow();
let folder = DriveApp.getFolderById("1W4pv0RW7DB_yh8pqChc8YPNyq0ETQ_1m");
for (let i = 0; i < lastRow-1; i++) {
let url = sheet.getRange(2+i,1).getValue();
let blob = UrlFetchApp.fetch(url).getBlob();
folder.createFile(blob);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment