This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Builds a TOC in the spreadsheet. | |
* | |
* Pablo Felip (@pfelipm). | |
* | |
* @param {true} includeId Include sheet ID | |
* @param {true} includeUrl Include link to sheet | |
* @return List of [Sheet name, Sheet ID, Sheet URL] | |
* @customfunction | |
*/ | |
function TOC(includeId, includeUrl) { | |
const ss = SpreadsheetApp.getActive(); | |
const baseUrl = ss.getUrl(); | |
const toc = []; | |
ss.getSheets().forEach(sheet => { | |
const rowResult = []; | |
rowResult.push(sheet.getName()); | |
if (includeId) rowResult.push(sheet.getSheetId()); | |
if (includeUrl) rowResult.push(baseUrl + '#gid=' + sheet.getSheetId()); | |
toc.push(rowResult); | |
}); | |
return toc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment