How Google Sheets Can Help You Create Custom QR Codes for Free
Stop being beholden to random websites to generate your QR Codes!
QR codes are everywhere! But did you know that you can create your own QR codes within Google Sheets without requiring any 3rd party plug-in? In this article, I will show you how to generate QR codes for any text or URL using Google Sheets and Google Apps Script.
Google Apps Script is a rapid application development platform that lets you create business applications that integrate with Google Workspace. You can use it to automate tasks, create custom functions, and add functionality to your Google Sheets.
Are you ready to learn how to create QR codes in Google Sheets? Let’s get started!
What you will need for this project:
- Google Sheet
- Google Drive Folder URL
Step 1: Set Up Your Google Sheet
I kept mine pretty simple and I just had a column for URLs and another one where I will have the application paste the link to the newly created QR code image.
Step 2: Open the Apps Script Editor
On the toolbar, you will select Extensions → Apps Script. This will open a new window in your browser. This is where you will add all the code for the project.
Step 3: Copy the Code
You will simply copy the code below into the Apps Script Editor with one minor change.
There is a line in the code that looks like this:
const folder = DriveApp.getFolderById('YOUR_GOOGLE_DRIVE_FOLDER_ID');
You will want to replace that string with your own FolderID. The way you can get the Google Drive folderID is by opening a Google Drive Folder and copying the URL and grabbing everything after the last /
Here is the code:
function onOpen(){
const ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Menu')
.addItem('Create QR Code','createQRCode')
.addToUi()
}
function createQRCode(){
const activeCell = SpreadsheetApp.getActiveRange();
const cellValue = activeCell.getValue();
var imageData = UrlFetchApp.fetch('https://chart.googleapis.com/chart', {
'method': 'post',
'payload': {
'cht': 'qr', // chart type
'chl': cellValue, // data for QR code
'chs': '300x300' // size of image
}
}).getBlob(); // get image data as blob
// create a file in Google Drive with image data
const folder = DriveApp.getFolderById('YOUR_GOOGLE_DRIVE_FOLDER_ID');
let file = folder.createFile(imageData)
// set file name as qrCode.png
file.setName(`${cellValue}_qrCode.png`);
// return file id
SpreadsheetApp.getActiveSheet().getRange(activeCell.getRow(), activeCell.getColumn()+1).setValue(file.getUrl())
return file.getId();
}
Step 4: Run the onOpen Function
At the top of the Apps Script editor you will see a banner that looks like this:
You will want to make sure in the drop-down that it says onOpen. Now you will click “Run.”
You will get a pop-up that is going to ask for your permission to execute the script.
Step 5: Go back to the Google Sheet
In a cell underneath URL you can type in any URL. Once you have done that you will want to make sure that cell is still selected and you can click on the button in the Google Sheets toolbar that says “Custom Menu.”
Once you click that you will see “Create QR Code.” Click that button and watch the magic!
Step 6: Scan your QR Code
The function is going to paste the URL of the file and if you hover over that you should get a preview of your QR code that you can scan.
In this article, I have shown you how to create QR codes within Google Sheets using Google Apps Script.
I hope you have enjoyed this tutorial and found it useful. If you have any questions or feedback, please let me know in the comments section below. And don’t forget to share this article with your friends and colleagues who might be interested in creating QR codes within Google Sheets!