Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement move tab under sheet #new #570

Closed
fabceolin opened this issue Jul 26, 2018 · 2 comments
Closed

Implement move tab under sheet #new #570

fabceolin opened this issue Jul 26, 2018 · 2 comments

Comments

@fabceolin
Copy link

Hi,

We are working with a sheet with a lot of tabs. New tabs are created without a pattern and manage this manually is time-consuming. We would like the possibility to move tabs, like here:
https://stackoverflow.com/questions/16401749/how-to-move-sheet-within-google-spreadsheeet-using-apps-script)

Thanks

@fabceolin fabceolin changed the title Implement move tab under sheet #new Implement move tab under sheet label:"Feature Request" Jul 26, 2018
@fabceolin fabceolin changed the title Implement move tab under sheet label:"Feature Request" Implement move tab under sheet label #new Jul 26, 2018
@fabceolin fabceolin changed the title Implement move tab under sheet label #new Implement move tab under sheet #new Jul 26, 2018
@robin900
Copy link
Contributor

@fabceolin That would be a nice feature; in the Sheets API, it is accomplished by modifying the integer index property of each worksheet (what you are calling a "tab") that belongs to a single spreadsheet.

If this feature were added, would you like it to be implemented so that you can pass a list of the Worksheet (tab) objects ordered the way you want them ordered, and then gspread does the necessary operations? Or do you want to update each Worksheet (tab) object's index property individually?

# 1) Order the Worksheets the way you'd like, set that order in a single call.
worksheets = my_sheet.worksheets()
worksheets = worksheets.sorted(lambda w: w['title'])
my_sheet.reorder_worksheets(worksheets)

# 2) update index for each worksheet.
worksheets = my_sheet.worksheets()
worksheets = worksheets.sorted(lambda w: w['title'])
for index, wksht in enumerate(worksheets):
    wksht.update_index(index)

Approach #1 makes only one API call; approach #2 allows fine grained control of the index property. We could implement one or both approaches in one pull request.

@fabceolin
Copy link
Author

fabceolin commented Jul 26, 2018

The approach 2 solve my problem. I only need to force the new created worksheet to appear at the end.

robin900 added a commit to robin900/gspread that referenced this issue Jul 26, 2018
Adds `Spreadsheet.reorder_worksheets` with test coverage and
documentation.

Adds `Worksheet.update_index` with test coverage and documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants