Stack Exchange
Inserting a QR Code generated from a formula in Google Sheets to Google Docs
I currently have this code which I got online and fitted it to mine.
//worksheets
const ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("QR CODE GENERATOR");
//lastrow
const lastrow_ws = ws.getLastRow();

function qrCode(){
  var documentID = ws.getRange(lastrow_ws, 10).getValue();
  Logger.log(documentID)
  var doc = DocumentApp.openById(documentID)
  var qrCode = ws.getRange(lastrow_ws, 2).getValue(); // Get the QR code value from the Spreadsheet
  var url = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=&" + qrCode 
  var resp = UrlFetchApp.fetch(url); // Get the image of QR code
  var barcode = doc.getChild(24).asParagraph().appendInlineImage(resp.getBlob()); // Value of child depend of where you want your QR code.
}

Currently it does place the QR Code but not the QR Code generated from the link provided in the Sheets. The QR code placed redirects you to Google searching CellImage which I don't understand. It is my first time handling QR codes.
Screenshots
Google spreadsheets QR:

Google Docs QR below:


About but not the QR Code Generated from the link provided in the Sheets, when I saw your script, it seems that var qrCode = ws.getRange(lastrow_ws, 2).getValue(); is the value of column "B". And, when I saw your sample image of Spreadsheet, it seems that column "B" is images inserted with a formula. I thought that this might be the reason for your current issue.
It seems that the formula uses a value from column "E". From this situation, how about the following modification?
From:
var qrCode = ws.getRange(lastrow_ws, 2).getValue();

To:
var qrCode = ws.getRange(lastrow_ws, 5).getValue();

or
var qrCode = encodeURIComponent(ws.getRange(lastrow_ws, 5).getValue());


By this modification, the value is retrieved from column "E" as qrCode of var url = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=&" + qrCode.


Thank you for replying! unfortunately, after I've tried it, it just returns the broken QR Code still with no URL when a camera is used.

Oh nevermind! I Fixed it. There was actually a & at the end of the URL QR Generator which wasn't supposed to be there. Your fix helped the code though. Thanks as always Tanaike! I have another question though i will be posting it for another question. Thanks!

@Dean Thank you for replying. Now, I noticed that in the case of var url = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=&" + qrCode, this might be var url = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" + qrCode. Please confirm it again.
