关于如何使用从其电子表格的html表单接收的数据创建pdf并通过电子邮件发送pdf文件的Google应用程序脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于如何使用从其电子表格的html表单接收的数据创建pdf并通过电子邮件发送pdf文件的Google应用程序脚本相关的知识,希望对你有一定的参考价值。
关于如何从电子表格的html表单接收的数据中创建pdf并通过电子邮件发送pdf文件的Google应用程序脚本-我想通过自定义html表单从工作表中记录的数据创建pdf文件
我有一个简单的带有电子邮件发送功能的html表单
这是索引html FORM文件:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function submitForm(form)
google.script.run
.withSuccessHandler(function(value)
document.getElementById('message').innerHTML = value;
document.getElementById('name').value = '';
document.getElementById('email').value = '';
document.getElementById('comment').value = '';
)
.submitData(form);
</script>
<?!= include("css");?>
</head>
<body>
<h2>Feedback Form</h2>
<div id="message"></div>
<br /><input id="button-responder" style="display:none;" type ="button" onclick="submitResponder();" value = "Nuova iscrizione">
<form id="my-form">
<br /><input id="name" type="text" name="name" placeholder="Your Name">
<br /><input id="email" type="email" name="email" placeholder="Your Email">
<br /><textarea id="comment" rows="10" cols="40" name="comment"></textarea>
<br /><input id="btn" type="button" value="Submit" onclick="submitForm(this.parentNode),document.getElementById('my-form').style.display='none',submitResponder('button-responder');" />
</form>
<?!= include("test-js");?>
</body>
</html>
此带有别名电子邮件的Google脚本:
function doGet(request)
return HtmlService.createTemplateFromFile('index')
.evaluate();//not all caps but it has to match the name of the file and it doesn't - Change to PAGE
function include(filename)
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
function submitData(form)
var subject='New Feedback';
var body=Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
var aliases = GmailApp.getAliases()
Logger.log(aliases); //returns the list of aliases you own
Logger.log(aliases[0]); //returns the alias located at position 0 of the aliases array
GmailApp.sendEmail('my-email@my-email.com','From an alias', 'A message from an alias!', 'from': aliases[0],subject: subject,htmlBody: body);
return Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
function userClicked(userInfo)
var url = "https://docs.google.com/spreadsheets/x/xx-xx-xxx_-xxxxxxxxxx-xxxx/edit#gid=x";
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("Data");
ws.appendRow([userInfo.name, userInfo.email, userInfo.comment]);
这是自定义javascript文件(“ test-js”):
<script>
function submitResponder()
var x = document.getElementById("button-responder");
var xx = document.getElementById("my-form");
var xxx = document.getElementById("message");
if (x.style.display === "none")
x.style.display = "block";
xx.style.display = "none";
xxx.style.display = "block";
else
x.style.display = "none";
xx.style.display = "block";
xxx.style.display = "none";
document.getElementById("btn").addEventListener("click",doStuff);
function doStuff()
var userInfo =
userInfo.name = document.getElementById("name").value;
userInfo.email = document.getElementById("email").value;
userInfo.comment = document.getElementById("comment").value;
google.script.run.userClicked(userInfo);
document.getElementById("name").value= "";
document.getElementById("email").value= "";
document.getElementById("comment").value= "";
</script>
这是一个简单的CSS样式文件(“ css”):
<style>
#message
color: red;
</style>
我正在寻找一个公式,通过获取在表单中输入的数据并通过电子邮件发送来创建pdf文件。该文件必须在驱动器中的特定文件夹/子文件夹中创建。文件名必须重播在表单上编辑的“名称”字段。
现在是最重要的部分。我希望pdf文件的链接仅显示在html页面上,而不显示在电子邮件中,如下例所示:
return Utilities.formatString ('name:% s <br /> Email:% s <br /> Comment:% s', form.name, form.email, form.comment)
link to PDF file
提前感谢您的帮助!
新问题!
关于下述功能:
function submitData(form)
var subject='New Feedback';
var body=Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
var folderId = "my-folder-ID"; // Please set the folder ID. // Added
var blob = Utilities.newBlob(body, MimeType.HTML, form.name).getAs(MimeType.PDF); // Added
var file = DriveApp.getFolderById(folderId).createFile(blob); // Added
var aliases = GmailApp.getAliases()
Logger.log(aliases); //returns the list of aliases you own
Logger.log(aliases[0]); //returns the alias located at position 0 of the aliases array
GmailApp.sendEmail('my-email@my-email.com','From an alias', 'A message from an alias!', 'from': aliases[0],subject: subject,htmlBody: body, attachments: [blob]); // Modified
// return file.getUrl(); // Modified
return Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s<br />PDF: %s', form.name,form.email,form.comment,file.getUrl());
我正在寻找一种试图以通用的测试格式返回的形式,该函数可以单击“查看您的PDF文件”类型,而不是在函数中输入URL地址:
return Utilities.formatString ('name:% s <br /> Email:% s <br /> Comment:% s <br /> PDF:% s', form.name, form.email, form.comment, file. getUrl ());
我希望可以使用基本文档作为模板来创建类似于以下内容的PDF文件:https://jeffreyeverhart.com/2018/09/17/auto-fill-google-doc-from-google-form-submission/请记住,我的应用程序是自定义html表单,如您从上方看到的那样。
提前感谢您的帮助!
- 您想将
var body=Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
转换为PDF文件。 - 您要将创建的PDF文件放入Google云端硬盘中的特定文件夹。
以上是关于关于如何使用从其电子表格的html表单接收的数据创建pdf并通过电子邮件发送pdf文件的Google应用程序脚本的主要内容,如果未能解决你的问题,请参考以下文章