0

我目前正在创建一个可以执行以下操作的脚本:

1.) 提交 Google 表单 2.) 将其存储在 Google Sheets 电子表格中 3.) 使用 Google Doc 模板将提交的数据转换为 PDF 4.) 将 PDF 存储在 Google Drive 中并添加到电子表格的链接 5.)将 PDF 作为附件通过电子邮件发送给提交 Google 表单的人。

目前,我处于第 3 步,在您提交表单“TypeError:无法从未定义中读取属性“Company”。(第 16 行,文件“代码”)”后,我不断收到以下信息。“公司”是我的谷歌表中标题的标题,来自我表单中的一个问题。我仔细检查了名称、空格和其他可能影响它的东西,但我仍然不断收到这个错误。我尝试与其他人一一进行,但我得到相同的错误,或者我得到“TypeError:无法读取未定义的属性'0'”。请帮忙!

function formSubmit(e) {
  const info = e.name;
  createPDF(info);
}

function createPDF(info){

  const pdfFolder = DriveApp.getFolderById("1Q9pB4n14m9VEikouQ-_WWx5LIAgDxhAL");
  const tempFolder = DriveApp.getFolderById("14iJEpwsb1KpeIYdcmQGuakyN9DmJXa9U");
  const templateDoc = DriveApp.getFileById("1DiCDrHhqxVWaVn8uxx3sExM3dl45VPLKxFmqy6xL9oc");

  
const newTempFile = templateDoc.makeCopy(tempFolder);
const openDoc = DocumentApp.openById(newTempFile.getId());
const body = openDoc.getBody();
  body.replaceText("{C}", info['Company'][0]);
  body.replaceText("{pName}", info['Print Name '][0]);
  body.replaceText("{Date}", info['Date'][0]);
  body.replaceText("{lName}", info['Last Name'][0]);
  body.replaceText("{fName}", info['First Name'][0]);
  body.replaceText("{mName}", info['Middle Name'][0]);
  body.replaceText("{dName}", info['Department Name'][0]);
  body.replaceText("{emName}", info['Engagement Manager Name'][0]);
  body.replaceText("{srAnswer}", info['Your Services and Responsibilities'][0]);
  body.replaceText("{listAanswer}", info['"LIST A": '][0]);
  body.replaceText("{listBanswer}", info['"LIST B":'][0]);
  body.replaceText("{listCanswer}", info['"LIST C":'][0]);
    
openDoc.saveAndClose();
    
  
  
  
  
 const blobPDF = newTempFile.getAs(MimeType.PDF);
 const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Print Name'][0] + " " + "Completed Onboarding Packet");
 tempFolder.removeFile(newTempFile);
    
}
4

0 回答 0