Created
June 9, 2022 23:55
-
-
Save palumbo/d751841c3e61764f058fb60253bc47fe 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
@itoldusoandso The things that you tweaked the code for sound exactly like what I need. I'm working on an automation using Make that posts to Instagram from a Google Sheet that was populated by a form filled out on a Wix site. Would you mind sharing your tweaked code with me?
@palumbo Thanks for making the YouTube video and sharing the code!