简体   繁体   English

Google Appscript 自动填充另一张纸

[英]Google Appscript autofill another sheet

I don't know if this is a bit of a complicated one.我不知道这是否有点复杂。 My google form is linked to a google sheet and I have a script that when a form is submitted it copies a google doc template and automatically fills in the relevant parts.我的谷歌表单链接到谷歌表格,我有一个脚本,当提交表单时,它会复制一个谷歌文档模板并自动填写相关部分。

What I'd like is that instead of filling a doc template, it fills a sheet template.我想要的是它不是填充文档模板,而是填充工作表模板。 My script is currently set up to look for specific text in the document and replace it with the relevant cell information我的脚本当前设置为查找文档中的特定文本并将其替换为相关的单元格信息

You can use createTextFinder and then get the range of the current match of the TextFinder您可以使用createTextFinder然后获取TextFinder当前匹配的范围

function getText() {
  try {
    let spread = SpreadsheetApp.getActiveSpreadsheet();
    let sheet = spread.getSheetByName("Sheet1");
    let text = sheet.createTextFinder("{{IS_5}}");
    console.log(text.findNext().getA1Notation());
  }
  catch(err) {
    console.log(err)
  }
}

8:19:03 AM  Notice  Execution started
8:19:04 AM  Info    A6
8:19:04 AM  Notice  Execution completed

Here is a simple onFormSubmit(e) installed trigger.这是一个简单的 onFormSubmit(e) 安装触发器。 It gets the latest event info, copies a spreadsheet template and replaces the string {{value}} with the form value.它获取最新的事件信息,复制电子表格模板并将字符串 {{value}} 替换为表单值。

function onFormSubmit(e) {
  try {
    Logger.log(JSON.stringify(e));
    let spread = SpreadsheetApp.openById("xxxxxxxxxxxxxxxxxxx");
    let copy = spread.copy("Copy of "+spread.getName());  // copy the template
    let text = copy.createTextFinder("{{value}}");
    let range = text.findNext();
    range.setValue(e.namedValues.Test[0]);
  }
  catch(err) {
    Logger.log(err);
  }
}

Reference参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM