Custom Functions - Get Sheet Names

Поделиться
HTML-код
  • Опубликовано: 18 сен 2024
  • How to write a custom function and return the sheet names.
    Sheet (to copy from the File menu):
    docs.google.co...
    Scripts:
    /**
    * Returns the name of the current tab.
    * @return Current tab name.
    * @customfunction
    */
    function sheetname(){
    return SpreadsheetApp.getActive().getActiveSheet().getName();
    }
    /**
    * Returns the names of all tabs in the spreadsheet.
    * @return A vertical array of all tab names.
    * @customfunction
    */
    function sheetnames(){
    const sheets = SpreadsheetApp.getActive().getSheets();
    let out = [];
    for (let i in sheets){
    out.push([sheets[i].getName()]);
    }
    return out;
    }
    /**
    * Returns the names of all tabs in the spreadsheet.
    *
    * @param {boolean} includes_current Whether to include the current tab in the output. TRUE by default.
    * @return A vertical array of all tab names.
    * @customfunction
    */
    function sheetnames(includes_current){
    const sheets = SpreadsheetApp.getActive().getSheets();
    let out = [];
    if (includes_current == false){
    for (let i in sheets){
    if (sheets[i].getName() == SpreadsheetApp.getActive().getActiveSheet().getName()) continue;
    out.push([sheets[i].getName()]);
    }
    } else {
    for (let i in sheets){
    out.push([sheets[i].getName()]);
    }
    }
    return out;
    }
    Connect with me:
    • spencer.farris@gmail.com
    • spencerfarris.me
    • www.linkedin.com/in/spencer-farris/
    • Twitter @FarrisSpencer
    • Google Product Expert support.google.com/docs/profile/12305

Комментарии • 11

  • @nuggsta35
    @nuggsta35 2 года назад +1

    Been checking out lots of channels and your explanations and tempo are Right on. Subbed.
    Keep up the content!

  • @zaccoza
    @zaccoza 2 года назад +1

    The listed name does not change when the page name is changed.
    It doesn't change when it's updated.
    Changed names are renewed when the command is re-entered

  • @zaccoza
    @zaccoza 2 года назад

    Useful work thanks 👏

  • @gsa1440
    @gsa1440 5 месяцев назад

    It's a shame that we weren't able to dynamically retrieve the name of the spreadsheet with Aps Script without using a function in the spreadsheet, which in this case is impractical in the end.

    • @SpencerFarris
      @SpencerFarris  5 месяцев назад

      Huh? Apps script can easily get it without a function in the spreadsheet. This is how to use Apps Script to put the sheet names in the spreadsheet

  • @dhurtado41595
    @dhurtado41595 2 года назад

    Is there a way to bulk rename tabs based on a list? For example I have a list of student names, and would like to create a tab for each of those names.

  • @kreativkaye
    @kreativkaye 2 года назад

    Is it possible to get the list of sheets from another Google spreadsheet file wthout having to run the script from the other file?

    • @SpencerFarris
      @SpencerFarris  2 года назад +1

      Sure. SpreadsheetApp.openById("sheet id").getSheets();

  • @nhattanktnn
    @nhattanktnn 24 дня назад

    How to enable dark mode in apps script editor?