To open a password-protected document, create a LoadOptions instance with the file format and set the password property.
fromgroupdocs.markdownimportMarkdownConverter,LoadOptions,FileFormatdefload_password_static():"""Open a password-protected document and convert using the static API."""# Step 1: Create load options with format and passwordload_options=LoadOptions(FileFormat.DOCX)load_options.password="secret"# Step 2: Convert the protected document using keyword argumentMarkdownConverter.to_file("protected.docx","load-password-static.md",load_options=load_options)if__name__=="__main__":load_password_static()
protected.docx is sample file used in this example. Click here to download it.
**Confidential Memo**
From: Meridian Outdoor Co. — Strategy Team
Date: 2026-01-15
Subject: FY2026 M&A Targets
[TRUNCATED]
fromgroupdocs.markdownimportMarkdownConverter,LoadOptions,FileFormatdefload_password_instance():"""Open a password-protected spreadsheet and convert using the instance API."""# Step 1: Create load options with format and passwordload_options=LoadOptions(FileFormat.XLSX)load_options.password="secret"# Step 2: Open the protected document using keyword argument for load optionswithMarkdownConverter("protected.xlsx",load_options=load_options)asconverter:# Step 3: Convert and save the Markdown outputconverter.convert("load-password-instance.md")if__name__=="__main__":load_password_instance()
protected.xlsx is sample file used in this example. Click here to download it.
If the password is missing or incorrect, a DocumentProtectedException is raised. You can catch it to display a user-friendly message:
fromgroupdocs.markdownimportMarkdownConverter,DocumentProtectedExceptiondefload_password_exception():"""Handle incorrect or missing passwords when opening protected documents."""try:# Step 1: Attempt to convert without providing a passwordMarkdownConverter.to_file("protected.docx","load-password-exception.md")exceptDocumentProtectedExceptionasex:# Step 2: Catch the exception and write a user-friendly message to a filewithopen("load-password-exception.txt","w",encoding="utf-8")asf:f.write(f"Cannot open document: {ex}\n")if__name__=="__main__":load_password_exception()
protected.docx is sample file used in this example. Click here to download it.
load-password-exception.md is the output produced by this example. Click here to download it.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.