简体   繁体   English

从单元格自动重命名 Google Sheets 文件

[英]Renaming Google Sheets File Automatically From A Cell

I'm a complete novice to script, so please forgive my ignorance.我是一个完整的脚本新手,所以请原谅我的无知。

I'm trying to run a script so that when a new sheet is made of a specific set of sheets I use for my clients, that new copy renames itself upon the input of a specific cell (C13) where my clients will enter their name.我正在尝试运行一个脚本,以便当新工作表由我为客户使用的一组特定工作表组成时,该新副本会在输入特定单元格 (C13) 时自行重命名,我的客户将在其中输入他们的姓名.

I should add I was using the following code that i grabbed from a similar question on here:我应该补充一点,我使用的是从这里的类似问题中获取的以下代码:

function onOpen() { 
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var C13 = ss.getRange("C13").getValue(); 
  var name = C13; 
  SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet("name"); 
}

But this only worked for when the sheet opened, and obviously with nothing in C13 this isn't useful但这仅在工作表打开时有效,显然 C13 中没有任何内容,这没有用

Thank you谢谢

If you wish that the sheet gets renamed when a specific range gets edited than you can use onEdit() trigger.如果您希望在编辑特定范围时重命名工作表,则可以使用onEdit()触发器。

The code below will replace the sheet's name with C13 cell's value if you change it.如果您更改它,下面的代码将用 C13 单元格的值替换工作表的名称。

function onEdit(e) { 
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var name = ss.getRange("C13").getValue(); 
  
  if(e.range.getA1Notation() == 'C13' && name!= '') {
    SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet(name);
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM