问题
I have a Google Sheet spreadsheet with some javascript code in it. The user(s) begin on a default sheet and the code creates and names a sheet based on the user that is accessing it. There is a bunch of code that copies data to their sheet, formats it, resize columns, etc. That all works fine. All I want to do is have the focus the user sees change from the default entry sheet to the custom sheet that was created for the user.
I've tried using:
sheet.activate()
sheet.setCurrentCell(cell)
ss.getSheetByName(username)
but none of these change the active sheet on screen (UI), it just changes the focus of the script that running.
I can't use
ss.getSheets()[1]
because there may be multiple users in the spreadsheet and their personalized sheet may not necessarily be the second.
I'm not getting any errors, I'm just not getting the UI to change focus to a different sheet.
回答1:
Try it with ss.setActiveSheet(ss.getSheetByName(username))
since the documentation states that 'Google Sheets UI displays the chosen sheet'.
来源:https://stackoverflow.com/questions/56261446/in-google-sheets-how-do-you-change-the-sheet-that-the-user-sees