I am generating QR codes in a column in Google Sheets with data entered via a Google Forms, and I would like to save them as images.
I'm want to generate QR Code in a row in Google Sheets, and I would like to save them as images. I cant copy the image generated by this function :
=image("https://image-charts.com/chart?chs=150x150&cht=qr&choe=UTF-8&chl="&ENCODEURL(B2))
Using Ctrl C and Ctrl V works only inside the Google Sheet and trying to copy and paste that one outside the sheet doesn't work either. The clipboard is detected as not containing images to paste elsewhere.
The problem is not in generating the QR, but exporting or saving it as an image to a folder in google drives. And I want the naming to be the links where the image (QR code) is generated, and the Column and row name to make sure that the image is the right QR Code Pictures.
I think this is can be accomplished by using google apps script
This is the Samples Sheets This is the Folder Link
CodePudding user response:
Try
function uploadFile() {
var sh = SpreadsheetApp.getActiveSheet()
var datas = sh.getRange('B2:B' sh.getLastRow()).getValues()
datas.forEach(function (data) {
if (data != '') {
var imgurl = "https://image-charts.com/chart?chs=150x150&cht=qr&choe=UTF-8&chl=" encodeURI(data)
var image = UrlFetchApp.fetch(imgurl).getBlob().getAs('image/jpeg').setName(data);
var folder = DriveApp.getFolderById('________your folder id_____');
var file = DriveApp.createFile(image);
Drive.Files.update({ "parents": [{ "id": folder.getId() }] }, file.getId());
}
})
}
enable drive api and put your folder id inside the script
or, put checkboxes in column A and put a trigger for this function
function uploadQRCode(event) {
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if (s.getName() == "Sheet1" && r.getColumn() == 1 && r.getValue() == true) {
var imgurl = "https://image-charts.com/chart?chs=150x150&cht=qr&choe=UTF-8&chl=" encodeURI(r.offset(0,1).getValue())
var image = UrlFetchApp.fetch(imgurl).getBlob().getAs('image/jpeg').setName(r.offset(0,1).getValue());
var folder = DriveApp.getFolderById('________your folder id_____');
var file = DriveApp.createFile(image);
Drive.Files.update({"parents": [{"id": folder.getId()}]}, file.getId());
SpreadsheetApp.getActive().toast('QRCode "' r.offset(0,1).getValue() '" saved !')
}
}
