How to reset Google Form counter values using google apps script

主宰稳场 提交于 2019-12-14 01:55:03

问题


I have several Google forms which are reused frequently with around 300 - 400 form submission each time.

Until now, I have two ways to reset form, by hand:

  1. Deleting the form while keeping the form editor opened.
  2. Select the rows that contain form submissions, right click and choose "Delete ... rows".

With script, I've have no luck finding such method like form.reset(). The method .DeleteRows(fromRow, to Row) just delete the rows, but doesn't affect the counters.

So, how can I use Google apps script to automate the "reset form" task?
Or, how to mimic the second way in script?

Thank you!


回答1:


I have a working solution, that uses deleteRows(). I'm not sure why that didn't work for you, it would be interesting to see your code.

The new Forms product (February 2013) is quite different than the legacy forms - this solution will work on legacy forms only.

Anyway, here's what I have, with before & after screenshots. The tidy() function can be called by passing in the number of rows to be removed, or you can call it from a menu as demonstrated here. A more complete version of this script is available as a gist.

/**
 * Standard onOpen provided in script template.
 */
function onOpen() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var entries = [{name : "Read Data",functionName : "readRows"},
                 {name : "Tidy Form Responses", functionName : "tidy"}];
  sheet.addMenu("Script Center Menu", entries);
};

/**
 * Prompt user for the number of form response rows to remove, then delete them.
 * Assumes that the form responses are in the active sheet, that there is one
 * row of 'headers' followed by responses (in row 2).
 *
 * @param {number} thisMany (Optional) The number of rows to remove. If not
 *                          specified, user will be prompted for input.
 */
function tidy(thisMany) {
  if (tidy.arguments.length == 0) {
    thisMany = Browser.inputBox("How many responses should be tidied?");
  }

  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.deleteRows(2, thisMany);
}

Before

During

After




回答2:


Google Forms has created a new form editor (released just a few weeks ago). This new form editor has an option for "Delete all responses." So one option would be to re-create the form in the new form editor. (From a new spreadsheet, click Tools > Create a form).

Note: This new form editor isn't available to Google Apps users yet.



来源:https://stackoverflow.com/questions/15020392/how-to-reset-google-form-counter-values-using-google-apps-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!