清除第二天表单条目上的脚本错误 [英] Clear script error on next day form entries

查看:55
本文介绍了清除第二天表单条目上的脚本错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下脚本在每天的午夜清除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.

这篇关于清除第二天表单条目上的脚本错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆