Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom function get sheet name by gid #25

Open
oshliaer opened this issue Sep 11, 2018 · 1 comment
Open

Custom function get sheet name by gid #25

oshliaer opened this issue Sep 11, 2018 · 1 comment
Assignees
Labels

Comments

@oshliaer
Copy link
Owner

/**
 * Returns sheet's name by gid
 *
 * @param {number} gid The gid of the sheet.
 * @return {string} The name of the sheet.
 * @customfunction
 */

function getSheetNameByGid(gid){
  gid = +gid || 0;
  var res_ = undefined;
  var sheets_ = SpreadsheetApp.getActive().getSheets();
  for(var i = sheets_.length; i--; ){
    if(sheets_[i].getSheetId() === gid){
      res_ = sheets_[i];
      break;
    }
  }
  return res_.getName();
}
@oshliaer oshliaer self-assigned this Sep 11, 2018
@oshliaer
Copy link
Owner Author

/**
 * Returns sheet's name by gid
 *
 * @param {GoogleAppsScript.Spreadsheet.Spreadsheet} spreadsheet
 * @param {number} gid The gid of the sheet.
 * @return {string} The name of the sheet.
 * @customfunction
 */

function getSheetNameByGid(spreadsheet, gid){
  gid = +gid || 0;
  var res_ = undefined;
  var sheets_ =spreadsheet.getSheets();
  for(var i = sheets_.length; i--; ){
    if(sheets_[i].getSheetId() === gid){
      res_ = sheets_[i];
      break;
    }
  }
  return res_.getName();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant