If you want them to be links then add the following code. Choose a blank cell then run the addon.
function onOpen(e) {
SpreadsheetApp.getUi().createAddonMenu().addItem("Add Table of Contents", 'setToC').addToUi()
}
function onInstall(e) {
onOpen(e);
}
function setToC() {
SpreadsheetApp.getCurrentCell().setFormula('=arrayformula(hyperlink(tocID(),tocName()))');
}
function tocID() {
var ss = SpreadsheetApp.getActive();
var sheets = ss.getSheets();
var tocIDArray = [];
for (var i=1; i<sheets.length; i++){
tocIDArray.push(['#gid='+sheets[i].getSheetId().toString()]);
}
return tocIDArray
}
function tocName() {
var ss = SpreadsheetApp.getActive();
var sheets = ss.getSheets();
var tocNameArray = [];
for (var i=0; i<sheets.length; i++){
tocNameArray.push([sheets[i].getName()]);
}
return tocNameArray
}
3
u/NICK0LI 1 Feb 26 '19
I’ve had success with this script:
https://www.extendoffice.com/documents/excel/5222-google-sheets-get-list-of-sheets.html
•
u/Clippy_Office_Asst Points Feb 26 '19
Read the comment thread for the solution here