G Sheets Table of Contents Script

女生的网名这么多〃 提交于 2020-06-16 17:27:55

问题


For Google sheet workbooks that have several sheets, I create a Table of Contents sheet that lists all of the sheets in the workbook to increase ease of use for users. I have looked for an add-on, macro, or script that can speed up the process. No dice. Any ideas for how to automate the process of creating a new sheet that lists the names of all of the other sheets (One sheet name per cell) and then automatically links the cell to that sheet?


回答1:


script:

function SHEETLIST() {
try {
  var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets()
  var out = new Array( sheets.length+1 ) ;
  out[0] = [ "NAME" , "#GID" ];
  for (var i = 1 ; i < sheets.length+1 ; i++ ) out[i] = 
  [sheets[i-1].getName() , sheets[i-1].getSheetId() ];
  return out
}
catch( err ) {
  return "#ERROR!" }}

formula:

=SHEETLIST()

turn sheet names into active hyperlinks:

=ARRAYFORMULA(HYPERLINK("#gid="&
 QUERY(INDEX(SHEETLIST();;2); "offset 1"); 
 QUERY(INDEX(SHEETLIST();;1); "offset 1")))

and if you want to bind it to manual input you can use VLOOKUP like

=ARRAYFORMULA(IFNA(VLOOKUP(A1, HYPERLINK("#gid="&
 QUERY(INDEX(SHEETLIST();;2); "offset 1"); 
 QUERY(INDEX(SHEETLIST();;1); "offset 1")); 1; 0)))

where A1 is your "search cell"



来源:https://stackoverflow.com/questions/59428356/g-sheets-table-of-contents-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!