CreateSheetGID 関数を選択して実行

updateSheetName はシート名を先頭の2シート以降をシーケンシャルに設定

function CreateSheetGID() {
  var spreadsheet = SpreadsheetApp.getActive();

  var sheet = SpreadsheetApp.getActive().getSheetByName('GID');
  if(sheet == null) {
    spreadsheet.insertSheet('GID', 0);
  }
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('GID'), true);

  var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
  for (var i = 0 ; i < sheets.length ; i++) {
    Logger.log("\t" + sheets[i].getName() + "\t" + sheets[i].getIndex() + "\t" + sheets[i].getSheetId());

    spreadsheet.getRange('A'+ (i + 1).toString()).activate();
    spreadsheet.getCurrentCell().setValue(sheets[i].getName());

    spreadsheet.getRange('B'+ (i + 1).toString()).activate();
    spreadsheet.getCurrentCell().setValue(sheets[i].getSheetId());
  }

  Logger.log("OK");
}

function updateSheetName() {
  var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
  
  for (var i = 2 ; i < sheets.length ; i++) {
    Logger.log("\t" + sheets[i].getName() + "\t" + sheets[i].getIndex() + "\t" + sheets[i].getSheetId());

    sheets[i].activate().activate().setName("シート"+ (i -1));
  }

}

 

© 2024 Falco Tech Blog Suffusion theme by Sayontan Sinha