Проблема
Я полагаю, что это то, что вы пытаетесь достичь из своего объяснения:
Измените имя листа в зависимости от значения динамического c указанного c ячейка (в вашем случае C2)
Решение
Если лист является нашим активным листом
Вот фрагмент кода для достижения этой цели. Там есть комментарии, которые объяснят вам каждую его часть:
function onEdit() {
// get the active sheet of the spreadsheet
var sheet = SpreadsheetApp.getActiveSheet();
// get the cell value even after been edited
var cellValue = sheet.getRange('C2').getValue();
// rename the sheet according to that value
sheet.setName(cellValue);
}
Если лист является конкретным c листом, который мы хотим переименовать
Вот фрагмент кода для достижения этого. Там есть комментарии, которые объяснят вам каждую его часть:
function onEdit() {
// get all the sheets in the active spreadsheet
var sheets = SpreadsheetApp.getActive().getSheets();
// go over every sheet and check if it matches the id of the one we want to change the name
for (i=0;i<sheets.length;i++){
// if the id matches select that as our sheet
if(sheets[i].getSheetId()=="0.0"){
var sheet = sheets[i];
}
}
// get the cell value even after been edited
var cellValue = sheet.getRange('C2').getValue();
// rename the sheet according to that value
sheet.setName(cellValue);
}
Если вы хотите изменить имена нескольких листов по отношению к значениям ячеек столбца одного листа (как указано вами c case)
function onEdit() {
// get all the sheets in the active spreadsheet
var sheets = SpreadsheetApp.getActive().getSheets();
// Get sheet containing all names (in this case the first sheet)
var sheetWithNames = sheets[0];
// go over every sheet and assign the name of the appropiate cell of the first sheet
for (i=1;i<sheets.length;i++){
sheets[i].setName(sheetWithNames.getRange(i+1, 2).getValue());
}
}
Надеюсь, это помогло вам. Дайте мне знать, если вам нужно что-то еще или вы что-то не поняли. Гутен Абенд! :)