我已经修改了“本周最佳员工奖”,并且无法让它在提交后将准确的数据提取到我的文档中。
我的目标是:
1) 使用所需的详细信息填写表格
2) 让脚本收集这些详细信息并将它们插入到我的文档模板中的正确密钥持有者中
3)在带有标题更改的pdf中创建文档的“新”副本
4)电子邮件会很好但不是必需的,只要它保存新文档
我可以让它创建一个新文档并运行脚本,但它似乎没有从表单或电子表格中提取正确的(或任何)数据。它一直显示“未定义”,它应该显示我输入到表单中的值。请帮我看看我的错误。我确实花了几个小时试图弄清楚并重新编写代码。提前致谢!
以下是我正在使用的文档和电子表格、表单和脚本的链接。
https://docs.google.com/document/d/1A34uyNyMzp3o8XBzmIGqqfvCH6ocpQWN4HaZ5f4AiDk/edit
https://docs.google.com/spreadsheet/ccc?key=0AkKN7xCpxU54dENoZ0RoSnF1QXhQNnAyX3ZiNmVwRGc#gid=0
这是我当前的脚本:
function sendDocument() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = sheet.getLastRow(); // First row of data to process
var numRows = 1; // Number of rows to process // Fetch the range of cells
var dataRange = sheet.getRange(startRow, 1,2) // Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var ID = row[1]; // First column
var facility_name = row[2]; // Second column
// Get document template, copy it as a new temp doc, and save the Doc’s id
var copyId = DocsList.getFileById("1A34uyNyMzp3o8XBzmIGqqfvCH6ocpQWN4HaZ5f4AiDk")
.makeCopy("Copy of Mail Merge Doc template"+' for '+facility_name)
.getId();
// Open the temporary document
var copyDoc = DocumentApp.openById(copyId);
// Get the document’s body section
var copyBody = copyDoc.getActiveSection();
// Replace place holder keys/tags,
copyBody.replaceText('keyFacilityName', facility_name);
copyBody.replaceText('keyID', ID);
var todaysDate = Utilities.formatDate(new Date(), "GMT", "MM/dd/yyyy");
copyBody.replaceText('keyTodaysDate', todaysDate);
// Save and close the temporary document
copyDoc.saveAndClose();
// Convert temporary document to PDF by using the getAs blob conversion
var pdf = DocsList.getFileById(copyId).getAs("application/pdf");
// Delete temp file
DocsList.getFileById(copyId).setTrashed(false);
}}
我还在脚本开头尝试了以下两个选项,以从表单中“提取”数据以创建“新”文档,但没有成功...
// Global variables
docTemplate = “1A34uyNyMzp3o8XBzmIGqqfvCH6ocpQWN4HaZ5f4AiDk”;
docName = “Copy of Mail Merge Doc template”;
function sendDocument() {
// Full name and email address values come from the spreadsheet form
var ID = from-spreadsheet-form
var facility_name = from-spreadsheet-form
...继续上面的脚本...
和
// Global variables
docTemplate = “1A34uyNyMzp3o8XBzmIGqqfvCH6ocpQWN4HaZ5f4AiDk”;
docName = “Copy of Mail Merge Doc template”;
function onFormSubmit(e) {
// Full name and email address values come from the spreadsheet form
var ID = e.values[1];
var facility_name = e.values[2];
...继续上面的脚本...
如果可能,请提供帮助。