Created
April 2, 2024 02:46
-
-
Save 4EverBuilder/b8e35a5ff1932728d98a0e9fa5b25c34 to your computer and use it in GitHub Desktop.
Generate QR code images from a google sheet
This file contains 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
// Review each line. Replace the variables inline. TEST before try | |
// It expects a file which has name, suburb, state, url. You may have as many columns as you need. | |
// In a given drive, it will generate QR codes as PNG files (Name-Suburb-State.png) | |
// Original inspiration and instructions : https://stackoverflow.com/questions/69058384/export-images-from-google-sheets | |
function isImageToImage(){ | |
const ss = SpreadsheetApp.openById('XXXXXXXX'); // replace with your spreadsheet ID | |
const sheet = ss.getSheetByName('YYYYY'); // replace with sheet name | |
// row (4) and columns (A/B/C) | |
const urls = sheet.getRange(4,9, sheet.getLastRow()-1).getValues() ;//.flat(); | |
const names = sheet.getRange(4,2, sheet.getLastRow()-1).getValues() ; | |
const suburbs = sheet.getRange(4,5, sheet.getLastRow()-1).getValues() ; | |
const states = sheet.getRange(4,6, sheet.getLastRow()-1).getValues() ; | |
console.log("Found " , urls.length); | |
const folder = DriveApp.getFolderById('ZZZZZZZZ') ; /// replace with folder name | |
let i = 0; | |
urls.forEach(url => { | |
console.log(i , url); | |
const filename = names[i] + '-' + suburbs[i] + '-' + states[i] + '.png'; //replace with your own file name | |
let existing = folder.getFilesByName(filename); | |
if(existing && existing.hasNext()){ | |
console.log('Existing ' , filename , existing); | |
return ++i; | |
} | |
console.log('Downloading ' , filename); | |
const blob = UrlFetchApp.fetch("QRCODE SERVER" + url).getBlob(); // replace | |
const file = folder.createFile(blob); | |
file.setName(filename); | |
i++; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment