【问题标题】:Not sure if creating a script is the answer- any advice不确定创建脚本是否是答案 - 任何建议
【发布时间】:2020-08-11 14:56:32
【问题描述】:

如果可能,我正在尝试以表格形式自动化流程。我的例子如下。

Jane Doe 在表单(姓名、日期、电子邮件、她想教的课程)中填写一份调查问卷,然后该问卷会显示在回复电子表格中。约翰史密斯也填写了它,所以现在我的电子表格上有两行回复。我想知道谷歌表格是否可以在底部为简(sheet2)和另一个为约翰(sheet3)自动创建一个新选项卡(工作表)(对于每个调查回复等等),将他们所有的答案复制到他们自己的标签。这样做的原因是,我必须联系 Jane 并询问她其他问题,并且在底部有她自己的选项卡会更容易,我可以在其中添加其他信息。我还将学生姓名添加到她的标签中以跟踪他们。约翰和其他填写调查表的人也是如此。那有意义吗? 我在 Google Doc Editors 中发布了这个问题,他们建议我在这里提交,因为我可能需要运行一个脚本。

https://docs.google.com/spreadsheets/d/1akTLcXJnjwg8B-aSOP8JvrXBFRwXMkeluwi35WU1d98/edit?usp=sharing

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    解决方案

    您可以在 Apps 脚本中使用 Form Submit trigger 来触发我在下面提供的脚本,这样每次有人在您的链接电子表格中提交答案时,都会添加一个带有提交回复者姓名的新表格该提交的详细信息。

    使用以下脚本,该脚本在您的电子表格中具有自我解释的 cmets(在电子表格菜单栏中,转到 Tools-> Script Editor 并粘贴并保存以下内容):

    function FormSubmit() {
    // Get the sheet where all form responses are added
      var sheet = SpreadsheetApp.getActive().getSheetByName('Form Responses 1');
      
      // Get all the data from the new response. I have used the method
      //getRange(row,col,number rows, number columns) and getValues which as
      // it returns a 2D array I have flatten it for easier use latter on.
      var getData = sheet.getRange(sheet.getLastRow(), 1,1,5).getValues().flat();
      // Create new sheet setting its name to the property name that we had in our original
      // sheet
      var newSheet = SpreadsheetApp.getActive().insertSheet().setName(getData[1]);
      
      // iterate over all the questions and details in the form and copy their values from
      // the original sheet and paste them into the new sheet we just created
      for(i=0;i<getData.length;i++){
      newSheet.getRange(1, i+1).setValue(getData[i]);
      }
    }

    为了让它工作并在每次有答案时添加适当的工作表,您必须在脚本编辑器中转到菜单栏并选择编辑 -> 当前项目的触发器。这将带您进入一个新页面,您必须点击添加触发器并选择以下内容:

    • 要运行的函数:FormSubmit
    • 选择事件源:来自电子表格
    • 选择事件类型:提交表单时

    最后点击保存,您就可以开始了!

    我希望这对您有所帮助。让我知道您是否需要其他任何内容,或者您​​是否不理解某些内容。 :)

    【讨论】:

      猜你喜欢
      • 2019-04-14
      • 2011-04-06
      • 2013-07-25
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      • 2011-01-09
      • 1970-01-01
      • 2011-06-20
      相关资源
      最近更新 更多