清除响应后,Google Spreadsheet不会从顶部开始 [英] Google Spreadsheet doesn't start at top when responses are cleared

查看:60
本文介绍了清除响应后,Google Spreadsheet不会从顶部开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将表单数据输入到Google电子表格中的表单.该数据按提交顺序列出.

I have a form that inputs the form's data into a google spreadsheet. This data is listed in order of submission.

当我清除电子表格的内容时,将输入下一个数据,就像存在其他数据一样,x数或下一行.

When i clear the content of the spreadsheet, the next data is inputted as if the other data existed, x number or rows down.

  1. 数据
  2. 数据

清除

  1. (空)
  2. (空)
  3. 数据

这是我用来清除内容的脚本

Here is the script I'm using to clear the content

function clear() {
  var sheet =   SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/1IEcXuEtkwVmnOEeQE71YQcZTrSkFa1OjlP8JpXGonHk/edit#gid=2015797647').getSheetByName('Form Responses 1');
  var lastRow = sheet.getLastRow();
  var lastCol = sheet.getLastColumn();
  var range = sheet.getRange(2,2,lastRow,lastCol);
  range.clearContent();

我应该以其他方式清除还是选择要清除的数据?

Is there a different way i should be clearing or selecting the data to clear?

还是有一种删除行的方式来保持电子表格的格式?

Or is there a way to delete rows that keeps the formatting of the spreadsheet?

推荐答案

您应该删除行而不是清除行内容:

You should simply delete the rows instead of clearing their content :

    function clear() {
  //    var sheet =   SpreadsheetApp.getActive().getSheetByName('Form Responses 1');
      var sheet =   SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/1IEcXuEtkwVmnOEeQE71YQcZTrSkFa1OjlP8JpXGonHk/edit#gid=2015797647').getSheetByName('Form Responses 1');
      var lastRow = sheet.getLastRow();
      sheet.deleteRows(2,lastRow-1);
    }

如果您想保留工作表中的可用行总数(由于响应会自动插入新行,但谁知道...,这实际上不是必需的),请在代码末尾添加此行

if you want to keep the total number of available rows in your sheet (which is not really necessary since responses automatically insert new rows but who knows...) add this line at the end of the code

  sheet.insertRows(2,lastRow-1);

这篇关于清除响应后,Google Spreadsheet不会从顶部开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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