Home > other >  Python, solve the problem of pywin32 calls
Python, solve the problem of pywin32 calls

Time:02-14

Good predecessors, I am a fan of python, learning pywin32, recent difficulties in dealing with excel, my need is to put a excel table, the work book protection, and add the user allows editing area, workbook protection can be realized, recorded by VBA to add allows editing area, change to win32com, always remind error, please can you give me advice, thank you

The import time
Import win32com. Client as win32

Excel=win32. Dispatch (' excel. Application ')
Excel. DisplayAlerts=False # close warning
Excel. Visible Visible=False # program
Path=r "C: \ Users \ \ Desktop \ 31370 kk \ g.x LSX"

MyBook=excel Workbooks. Open (path)
MySheet=myBook. Worksheets (' Sheet1)
MySheet. Protect (" 1 ", True, True)
Time. Sleep (2)
MySheet. Protection. AllowEditRanges. Add (Title="ff", Range=mySheet Range (' a1: b34))

MyBook. The save ()
Excel. The Quit ()
.