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
Been checking out lots of channels and your explanations and tempo are Right on. Subbed.
Keep up the content!
Thank you!
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
Useful work thanks 👏
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.
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
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.
Is it possible to get the list of sheets from another Google spreadsheet file wthout having to run the script from the other file?
Sure. SpreadsheetApp.openById("sheet id").getSheets();
How to enable dark mode in apps script editor?
I use the AppsScript Color add on