如何在我的谷歌表单中添加我的谷歌应用程序脚本签名代码



我在网上找到了这段代码,它允许我用.gs和.html.绘制标志

function doGet() {
return HtmlService
.createTemplateFromFile('index')
.evaluate();
}
function saveToDrive(signature){
var signature = signature.split(",")
var blob = Utilities.newBlob(Utilities.base64Decode(signature[1]), 'image/png');
var sheet=SpreadsheetApp.getActive().getActiveSheet();
sheet.insertImage(blob, 1, 1);
}
<!DOCTYPE html>
<html>
<head><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/></head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/willowsystems/jSignature/master/libs/jSignature.min.js"></script>
<body>
<form>
...
Signature:
<div id="signature"></div><br>
<img id="rendered" src="" style="display:none">
<input type="Submit" value="Save" onclick="getSignature();"/>
...
</form>
</body>
<script>
document.getElementById("signature").style.border = "1px solid black";
$("#signature").jSignature({
'background-color': 'transparent',
'decor-color': 'transparent'
});
function getSignature(){
$("img#rendered").attr("src",$('#signature').jSignature('getData','default'));
var signature = document.getElementById('rendered').src;
google.script.run.saveToDrive(signature);
} 
</script>
</html>

我只想知道我是如何将它集成到我的表单中的,这样在底部就有一个签名的地方,然后它会自动保存到我的谷歌驱动器中,并以图像的形式显示在我的表单上。

您可以调整代码片段以将签名保存到驱动器中,并将WebApp URL嵌入表单中

为此:

  • saveToDrive函数修改为
function saveToDrive(signature){
var signature = signature.split(",")
var blob = Utilities.newBlob(Utilities.base64Decode(signature[1]), 'image/png');
blob.setName("signature");
var file = DriveApp.createFile(blob);
}
  • 将代码部署为WebApp,设置为:Execute the app as:MeWho has access to the app:Anyone, even anonymous
  • 现在,我不知道如何将此WebApp嵌入谷歌表单(您需要为此创建一个自定义HTML表单(,但您可以做的是提供一个指向WebApp的链接,作为问题/响应选项的一部分,并请用户关注该链接

这是一个示例表单(请记住,WebApp是以我的身份部署的,因此如果您提供签名,它将保存在我的驱动器上,而不是您的驱动器上(:

https://docs.google.com/forms/d/e/1FAIpQLSckCxKzrUdNvpcONLVRvJ08e5EDZRNB-tTfSRKG2YRLVjI_Ww/viewform

相关内容

最新更新