Search code examples
pythonexcelxlwings

Xlwings / open password protected worksheet in xlsx?


I get an answer how to open a password protected xlsx with xlwings: Xlwings / open password protected xlsx?

wb = xlwings.Book("file.xlsx", password="Passw0rd!")

But can i also open and handle a worksheet in an xlsx - where only this specific worksheet of the xlsx is password-protected and not the whole xslx? Or the xlsx is only password-protected for writing (and reading is allowed)?

I tried this with the solution from the above link but this didn´t work for the situations as desccribed above.


Solution

  • 'Protect Sheet'.

    ws.api.Protect(Password='test')
    ws.api.Unprotect(Password='test')
    

    Other features under this setting (not full tested);

    ws.api.Protect(Password='test', DrawingObjects=True, Contents=True, Scenarios=True,
            UserInterfaceOnly=False, AllowFormattingCells=False, AllowFormattingColumns=True,
            AllowFormattingRows=False, AllowInsertingColumns=False, AllowInsertingRows=False,
            AllowInsertingHyperlinks=False, AllowDeletingColumns=False, AllowDeletingRows=False,
            AllowSorting=False, AllowFiltering=False, AllowUsingPivotTables=False)