从Google Sheet生成带有QR码的Google文档 [英] Generate google docs with QR code from google sheet

查看:116
本文介绍了从Google Sheet生成带有QR码的Google文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含很多单元格的Google表格,其中一个是QR码(QR码包含姓名和员工ID).通过替换占位符文本,基于工作表中的值生成Google文档文件.该Google文档将用作数字通行证.

I have a Google Sheet with many cells, one of which is a QR code (QR code contains name and Employee ID). A Google Docs file is generated based on the values from the worksheet, by replacing placeholder text. This Google Doc will be used as a digital pass.

如何将QR代码图像放置在Google表格中,该图像是根据Google表格数据生成的?

How can I place the QR code image in the Google Docs, generated from the Google Sheets data?

例如在工作表中,我将Employee IDNameQR Code存储在A,B和D列中. 我使用replaceText替换Document中的占位符文本:

Ex. In the sheet, I stored Employee ID, Name, and QR Code in columns A, B, and D.
I use replaceText to replace placeholder text in the Document:

      copyBody.replaceText('EmployeeID', row[i][0]);
      copyBody.replaceText('firstName', row[i][1]);
      copyBody.replaceText('qrCode', row[i][3]); etc.

QR码作为公式结果存储在工作表中:
=IMAGE("https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" & C2)

The QR Code is stored in the sheet as a formula result:
=IMAGE("https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" & C2)

运行脚本时,模板文档中的EmployeeIDName字段将替换为所需的值,但qrCode字段中的内容均未替换.

When I run my script, the EmployeeID and Name fields are replaced in the template document with the desired values, but nothing in the qrCode fields.

推荐答案

我不认为在电子表格单元格上生成的QR码正在考虑作为文本,因此该函数将不替换"qrCode".您应该使用上面的代码:

I don't think that the QR code that is generated on your Spreadsheet cell is considering as text, so the function will replace 'qrCode' by nothing. You should use the code above:

var doc = DocumentApp.openById('DocId')
var ss = SpreadsheetApp.openById('SsId');
var qrCode = ss.getRange('qrCode').getValue(); // Get the QR code value from te 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(0).asParagraph().appendInlineImage(resp.getBlob()); // Value of child depend of where you want your QR code. 

有关 appendInlineImage(blob)方法的详细信息 getChild(name)方法

这篇关于从Google Sheet生成带有QR码的Google文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆