使用二维码在谷歌表格中输入价值? [英] Using QR Code to enter value into Google Form?

查看:0
本文介绍了使用二维码在谷歌表格中输入价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google Form上有一个表单,用于记录访客进入我们停车场的情况。入场所需的数据之一是通行证号码,它是以二维码的形式递给参观者的。有没有办法不再手动输入通行证号码,只需扫描二维码,通行证号码就会输入到表格中?

我知道可以使用以下脚本在工作表中执行此操作:

function doGet(e){
  var ss = SpreadsheetApp.openByUrl("sheet_url");
  var sheet = ss.getSheetByName("sheet_name");
return insert(e,sheet);

}

function doPost(e){
  var ss = SpreadsheetApp.openByUrl("sheet_url");
  var sheet = ss.getSheetByName("sheet_name");
return insert(e,sheet);

}


function insert(e,sheet){
 
  var scannedData = e.parameter.sdata;
  var d = new Date();
  var ctime =  d.toLocaleString();
  
  sheet.appendRow([scannedData,ctime]);

因此,我希望在座的任何人都知道表单的脚本应该是什么样子。

推荐答案

当您访问部署为Web应用程序的应用程序脚本的URL时,您可以在发布Web应用程序时提供的URL后使用?参数将参数传递到脚本中的doGet(e)函数:

https://script.google.com/.../exec?passNo=21480&qNumber=1
e函数接受的e变量是一个事件对象,它包含有关事件的信息。You can acess the parameters from the URL using e.parameters

function doGet(e){
  Logger.log(e.parameters);
}

将在日志中显示 {qNumber=[1], passNo=[21480]}。可以提取这些参数,然后使用FormAppApps脚本库,您可以创建对表单的新响应,并使用FormAppcreateResponse().withItemResponse(ItemResponse)方法以编程方式提交它,使用从url参数获取的通行号和问题号:

Code.gs:

function doGet(e){
  try {
    var passNo = e.parameters.passNo;
    var qNumber = e.parameters.qNumber;
    
    var form = FormApp.openById('your-form-id-here');
    var items = form.getItems();

    // assuming question 1 is the pass number question
    var q = items[qNumber[0] - 1].asTextItem();   
    var itemResponse = q.createResponse(passNo[0])
    
    var FormResponse = form.createResponse();    
    FormResponse.withItemResponse(itemResponse);
    FormResponse.submit();
    
    return HtmlService.createHtmlOutputFromFile('Success')
  }
  catch(e){
    return HtmlService.createHtmlOutputFromFile('Failure'); 
  }
}

我还在项目中创建了两个HTML文件,分别名为‘Success.html’和‘Failure.html’,Web应用会根据响应创建和提交是否成功返回各自的页面:

Success.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    Success
  </body>
</html>

Failure.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    Failure
  </body>
</html>

现在您需要做的就是用脚本的URL和相关参数作为定位器生成一个二维码。确保将二维码中的pNumber参数始终设置为您要提交的问题的编号,并且URL中passNo=之后的数字是您要扫描和输入的通行号。

这篇关于使用二维码在谷歌表格中输入价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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