用于清除多个特定范围的脚本 - 无法调用 Null 的 getSheetByName 方法

Script to clear multiple specific ranges - Cannot call method getSheetByName of Null

本文关键字:调用 Null 方法 getSheetByName 脚本 用于 范围 清除      更新时间:2023-09-26

我试图遵循的示例

var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');

错误:

无法调用方法 getSheetByName of Null

指向错误的链接

我需要清除列中的数据。 如果有人能帮助我解决这个问题,我将不胜感激。

试试这个:

function resetColumns() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheetByName('Tools')
  sh.getRange("A1:A9").clearContent();
};

为了使 getSheetByName() 方法正常工作,必须将其链接到电子表格对象。 如果尚未定义该方法尝试处理的对象,则无法在对象中找到该方法。 在应用脚本面向对象编程中,该方法位于对象内部。 该方法不能作为独立函数调用。