首页 > 解决方案 > How to take total count of spreadsheets on my Google Sheet File

问题描述

Is there any native formula built into the Google Sheet File that I can use to identify the total number of sheets (Inclusive of Hidden Sheets as well) on the file?

If there is no native formula, is there any script I can run to check the same.

标签: google-apps-scriptgoogle-sheetsgoogle-sheets-formula

解决方案


没有本机公式,但您可以使用脚本:

function SNAME(option) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet()
  var thisSheet = sheet.getName(); 
  if(option === 0){                  // ACTIVE SHEET NAME =SNAME(0)
    return thisSheet;
  }else if(option === 1){            // ALL SHEET NAMES =SNAME(1)
    var sheetList = [];
    ss.getSheets().forEach(function(val){
       sheetList.push(val.getName())
    });
    return sheetList;
  }else if(option === 2){            // SPREADSHEET NAME =SNAME(2)
    return ss.getName();    
  }else{
    return "#N/A";                   // ERROR MESSAGE
  };
};

然后公式:

=COUNTA(SNAME(1))

推荐阅读