带有应用程序脚本的电子表格重命名事件

Spreadsheet rename event with apps script

是否可以收听 "Spreadsheet renamed" 事件?

对应的 event object 的 changeType 等于 'OTHER'。它在更改重命名 sheet 时起作用,但在重命名整个传播sheet 时不起作用。

您不能 运行 sheet 上的函数重命名,不。您可以从 Spreadsheet 绑定的脚本中执行此操作,但您需要设置一些属性并级联触发器。这是一个非常粗糙的工作示例:

// Globals
var ss = SpreadsheetApp.getActiveSpreadsheet();
var name = ss.getName();

// Each edit, check for a rename
function onEdit() {

  // Grab the stored name from opening
  var setName = PropertiesService.getDocumentProperties().getProperty("name");

  // Get the current name of the sheet.
  var currentName = SpreadsheetApp.getActiveSpreadsheet().getName();

  // If it doesn't match, there's been a rename. Log and reset the stored name.
  if(setName != currentName) {
    Logger.log("Renamed from " + setName + " to " + currentName);
    PropertiesService.getDocumentProperties().setProperty("name", currentName)
    // do something else
  }
}

// Store the name when the sheet is opened
function onOpen() {
  var currentName = PropertiesService.getDocumentProperties().setProperty("name", name);
  Logger.log(currentName.getProperty("name"));
}