Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This script will create a QR code for each record which ID is found in a especific tab within a Google Sheet
- userId is selected as row[0] where 0 means the column 1, change it according to your needs.
- The script will retrieve the current deployed script url and concatenate the userId parameter to it, so when
- a user scans the code it will be redirected to the information page of the especific user.
- This is only the part 1 of this project, part 2 url will be posted anytime soon right below, as of now the script below will generate QR codes per each user found in the selected Google Sheet Tab, just for reference while ago I posted a similar approach: https://pastebin.com/PEkbXm9F
- Web app needs to be deployed as "anyone even anonymous"
- The QR codes will be generated and stored in a Google Drive folder, codes needs to be shared with the Google User Account or "Public"
- Also the code URL of the file stored in Google Drive will populate another column in the Google Sheet tab
- */
- function generateQRCodes() {
- const sheet = SpreadsheetApp.openById('SPREADSHEET_ID').getSheetByName('SHEET_NAME');
- const data = sheet.getDataRange().getValues();
- const folderId = 'YOUR_DRIVE_FOLDER_ID';
- const webAppUrl = ScriptApp.getService().getUrl();
- const folder = DriveApp.getFolderById(folderId);
- data.forEach((row, index) => {
- if (index === 0) return;
- const userId = row[0]; // The userID is in the first column
- // Construct the URL for the QR code
- const qrContent = `${webAppUrl}?id=${encodeURIComponent(userId)}`;
- const qrCodeUrl = `https://chart.googleapis.com/chart?cht=qr&chl=${encodeURIComponent(qrContent)}&chs=200x200&choe=UTF-8`;
- const response = UrlFetchApp.fetch(qrCodeUrl);
- const blob = response.getBlob();
- const file = folder.createFile(blob).setName(`QR_${userId}.png`);
- sheet.getRange(index + 1, /* Column number for QR URL */).setValue(file.getUrl());
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment