清除第二天表单条目上的脚本错误

编程入门 行业动态 更新时间:2024-10-27 14:23:02
本文介绍了清除第二天表单条目上的脚本错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用以下脚本在每天的午夜清除Google表单条目.

I am using the following script to clear Google form entries at midnight each day.

function clearRange() { var sheetActive = SpreadsheetApp.openById("1DNeHRC41ryRY9s8wZmlqmoIEhm8MqD601BvqoV26V3o").getSheetByName("Form responses 1"); sheetActive.getRange('A2:E').clearContent(); }

问题:

  • 第二天,表单条目将从前一天条目下方的行而不是第二行开始添加到工作表中.

示例:

  • 昨天,在工作表上输入了10个表单条目(第2行至第11行).该脚本在午夜运行并清除条目.
  • 今天,在表单上输入了5个条目,但从第12行开始输入了这些信息.

我需要清除并重置工作表,以便每天开始在第2行中输入表单条目.

I need the sheet to clear and reset, to start entering form entries in row 2 every day.

这可能吗?如果是这样,需要对公式进行哪些更改?谢谢您的协助.

Is this possible? If so, what changes are needed to the formula? Thank you for your assistance.

推荐答案

解决方案:

尝试删除行:

function clearRange() { const sheetActive = SpreadsheetApp.openById("1DNeHRC41ryRY9s8wZmlqmoIEhm8MqD601BvqoV26V3o").getSheetByName("Form responses 1"); const form_size = sheetActive.getLastRow()-1; sheetActive.deleteRows(2, form_size); }

在开始使用此解决方案之前,仅是第一次,请手动删除所有行;否则,请执行以下操作.从第二行开始,直到将添加新条目之前的行.因此,新条目将在第二行.

Before you start using this solution, only for the first time, delete manually all the rows; starting from the second row until the row before the new entry will be added. So the new entry will be at the second row.

但是,不建议触摸表单回复表.我建议您创建一个单独的工作表,以仅查询今天的记录,并将原始数据放在表单回复工作表中.这样,您无需清除或删除旧的表单条目,而且也无需触摸将来可能用作参考的原始数据.

However, it is not recommended to touch the Form responses sheet. I would advice you to create a separate sheet to query only the records of today and let the raw data be in the Form responses sheet. In this way, you don't need to clear or delete the old form entries, but you also don't touch the raw data which might be used as a reference in the future.

  • deleteRows()
  • getLastRow()

更多推荐

清除第二天表单条目上的脚本错误

本文发布于:2023-11-24 02:53:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623707.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第二天   条目   表单   脚本   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!