Learn how to lock and unlock PowerPoint presentations in Python: https://blog.aspose.com/2021/12/27/lock-or-unlock-powerpoint-ppt-in-python/
Last active
May 10, 2023 11:27
-
-
Save aspose-com-gists/091486327848348c105b79e1bf2b16a7 to your computer and use it in GitHub Desktop.
Lock or Unlock PowerPoint Presentations in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load presentation | |
with slides.Presentation("presentation.pptx") as pres: | |
# loop through all the slides in the presentation | |
for slide in pres.slides: | |
for shape in slide.shapes: | |
# if shape is autoshape | |
if type(shape) is slides.AutoShape: | |
auto_shape_lock = shape.shape_lock | |
# apply locks | |
auto_shape_lock.position_locked = True | |
auto_shape_lock.select_locked = True | |
auto_shape_lock.size_locked = True | |
# if shape is group shape | |
elif type(shape) is slides.GroupShape: | |
group_shape_lock = shape.shape_lock | |
# apply locks | |
group_shape_lock.grouping_locked = True | |
group_shape_lock.position_locked = True | |
group_shape_lock.select_locked = True | |
group_shape_lock.size_locked = True | |
# if shape is a connector | |
elif type(shape) is slides.Connector: | |
connector_lock = shape.shape_lock | |
# apply locks | |
connector_lock.position_move = True | |
connector_lock.select_locked = True | |
connector_lock.size_locked = True | |
# if shape is picture frame | |
elif type(shape) is slides.PictureFrame: | |
picture_lock = shape.shape_lock | |
# apply locks | |
picture_lock.position_locked = True | |
picture_lock.select_locked = True | |
picture_lock.size_locked = True | |
# save the presentation file | |
pres.save("Locked.pptx", slides.export.SaveFormat.PPTX) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load presentation | |
with slides.Presentation("Locked.pptx") as pres: | |
# loop through all the slides in the presentation | |
for slide in pres.slides: | |
for shape in slide.shapes: | |
# if shape is autoshape | |
if type(shape) is slides.AutoShape: | |
auto_shape_lock = shape.shape_lock | |
# remove locks | |
auto_shape_lock.position_locked = False | |
auto_shape_lock.select_locked = False | |
auto_shape_lock.size_locked = False | |
# if shape is group shape | |
elif type(shape) is slides.GroupShape: | |
group_shape_lock = shape.shape_lock | |
# remove locks | |
group_shape_lock.grouping_locked = False | |
group_shape_lock.position_locked = False | |
group_shape_lock.select_locked = False | |
group_shape_lock.size_locked = False | |
# if remove is a connector | |
elif type(shape) is slides.Connector: | |
connector_lock = shape.shape_lock | |
# remove locks | |
connector_lock.position_move = False | |
connector_lock.select_locked = False | |
connector_lock.size_locked = False | |
# if shape is picture frame | |
elif type(shape) is slides.PictureFrame: | |
picture_lock = shape.shape_lock | |
# remove locks | |
picture_lock.position_locked = False | |
picture_lock.select_locked = False | |
picture_lock.size_locked = False | |
# save the presentation file | |
pres.save("Unlocked.pptx", slides.export.SaveFormat.PPTX) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment