Search code examples
pythongspread

Gspread hide sheets


I am trying to write a python script - connecting with google sheets (google sheets API & google drive API) - to generate weekly reports. I could not find a function to hide "old" sheets (from previous weeks) and leave just the recent one - any ideas?

As presented below - I have couple of sheets from different dates - it will be generated every week I would like to hide old sheets and leave the recent one (I do not want to do it manually) [1]: https://i.sstatic.net/aovBB.png


Solution

  • This solution works, with a new update - previous sheet is being hidden:
    
    
    
    sh_instance.batch_update(body={
        'requests': [
            {'updateSheetProperties': {
                'properties': {
                    'sheetId': sh_instance.get_worksheet(-2).id,
                    'hidden': True
                },
                'fields': 'hidden'
            }
            }
        ]
    }
    )
    

    https://docs.gspread.org/en/latest/api.html batch_update(body)