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));
  }

}

 

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

© 2024 Falco Tech Blog Suffusion theme by Sayontan Sinha