使用电子表格中的数据填写 gdocs 后创建 PDF
我编写了这个脚本来创建一个 gdocs,其中填充了来自 google 电子表格的数据:
function autoFillGoogleDocFromForm(e) {
var timestamp = e.values[0];
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
var theDate = curr_year + "0" + curr_month + curr_date;
var contractualpartner = e.values[2];
var address = e.values[3];
var companyno = e.values[4];
var signee = e.values[5];
var title = e.values[6];
var templateFile = DriveApp.getFileById("1eVqeRAyBPM4VDGlByDj3LAiDpzky2-eDO_pZz0IP_4E");
var templateResponseFolder = DriveApp.getFolderById("1OVUma_-u6RYaw8qVRbxH8yF58x0MCwd8");
var copy = templateFile.makeCopy(theDate + '_' + "YYY" + '_' + "XXX" + '&' + contractualpartner, templateResponseFolder);
var doc = DocumentApp.openById(copy.getId())
var body = doc.getBody();
body.replaceText("{{Partner}}", contractualpartner);
body.replaceText("{{Address}}", address);
body.replaceText("{{Company Number}}", companyno);
body.replaceText("{{Signee}}", signee);
body.replaceText("{{Title}}", title);
doc.saveAndClose();
}
该脚本运行良好。现在我想将创建的 gdocs 转换为 pdf 文档。 我花了几个小时寻找解决方案,但没有找到。我找到了一个解决方案,其中文件夹中的所有文档都会从 gdocs 转换为 pdf,但我只想转换电子表格中的新条目。每个 gdoc 应该只有一个 pdf 文档。
I wrote this script to create a gdocs filled with data from a google spreadsheet:
function autoFillGoogleDocFromForm(e) {
var timestamp = e.values[0];
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
var theDate = curr_year + "0" + curr_month + curr_date;
var contractualpartner = e.values[2];
var address = e.values[3];
var companyno = e.values[4];
var signee = e.values[5];
var title = e.values[6];
var templateFile = DriveApp.getFileById("1eVqeRAyBPM4VDGlByDj3LAiDpzky2-eDO_pZz0IP_4E");
var templateResponseFolder = DriveApp.getFolderById("1OVUma_-u6RYaw8qVRbxH8yF58x0MCwd8");
var copy = templateFile.makeCopy(theDate + '_' + "YYY" + '_' + "XXX" + '&' + contractualpartner, templateResponseFolder);
var doc = DocumentApp.openById(copy.getId())
var body = doc.getBody();
body.replaceText("{{Partner}}", contractualpartner);
body.replaceText("{{Address}}", address);
body.replaceText("{{Company Number}}", companyno);
body.replaceText("{{Signee}}", signee);
body.replaceText("{{Title}}", title);
doc.saveAndClose();
}
This script works perfectly. Now I would like to convert the created gdocs into a pdf document.
I have spent some hours searching for a solution but didn't find one. I found a solutions where all documents in the folder would be converted from gdocs to pdf but I would like to only convert the new entry in the spreadsheet. Every gdoc should have only one pdf document.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建 PDF驱动器 API V2。
必须启用
Create PDF
Drive API V2 must be enabled.