In Google Sheets, how do you change the sheet that the user sees?

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 14:23:17

问题


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

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