How to Programmatically Read a Restricted or Password-Protected Excel File
Question details
The user needs to extract and update data within restricted or password-protected Excel files using automation tools like Power Automate, Microsoft Graph, or Office Scripts.

- Product
- Microsoft Excel, Power Automate, Office Scripts
- Device & OS
- not provided
- Scenario
- Automating data extraction and modification in restricted business Excel workbooks.
- Observed behavior
- Automation tools like Microsoft Graph and Power Automate do not automatically bypass workbook protection or organizational rights management.
Ensure you have the valid password or appropriate organizational permissions (like Azure AD credentials) for the restricted Excel file, as automation platforms cannot bypass built-in security controls.
Manage Protection Using Office Scripts and Power Automate
Use Office Scripts within Power Automate to temporarily unprotect, update, and re-protect the workbook.
Microsoft Graph, Power Automate, and Office Scripts are designed to respect file security. They cannot natively bypass organizational rights management (IRM) or workbook passwords.
To automate actions on a protected file, you must use an Office Script to temporarily remove the protection, perform the required actions, and reapply the protection before the workflow ends.
Open Excel on the web, go to the 'Automate' tab, and click 'New Script' to open the Code Editor.
Add code to unprotect the worksheet using your password. For example: `workbook.getWorksheet('Sheet1').getProtection().unprotect('YourPassword');`
Below the unprotect command, write the code necessary to extract or update the required data in the worksheet.
At the end of your script, re-protect the worksheet to maintain security: `workbook.getWorksheet('Sheet1').getProtection().protect({password: 'YourPassword'});`
In Power Automate, add the 'Run script' action from the Excel Online connector and point it to the script you just created.

Consult Microsoft Office Development Communities
Seek specialized help for complex API integrations or specific programming language requirements.
Try WPS Office for Lightweight Excel Automation and File Security
If you are struggling with complex Microsoft Graph permissions or heavy Office automation limits, WPS Office offers a lightweight, free alternative. With robust support for VBA macros and seamless compatibility with Microsoft Excel formats, you can easily manage, protect, and automate your spreadsheets.
- 1. Download and Install: Download WPS Office from the official website and complete the installation.
- 2. Open Your Protected File: Launch WPS Spreadsheets and open your .xlsx file. You will be prompted to enter your password normally.
- 3. Automate via VBA: Go to the Developer tab and use the built-in VBA editor to write macros for local automation of your encrypted files.

Frequently Asked Questions
Can Microsoft Graph API read a password-protected Excel file directly?
No, Microsoft Graph API cannot automatically bypass workbook protection. You must either provide the password securely if the specific endpoint supports it, or remove the password manually before using Graph to read the file.
How do I read an encrypted Excel file using Python?
You can use third-party libraries like `msoffcrypto-tool` to decrypt the Excel file using the password into a temporary memory stream, which can then be read and processed by standard libraries like `pandas` or `openpyxl`.
Is it possible to use Power Automate to unlock an Excel file?
Standard Excel connectors in Power Automate do not natively support passing passwords to unlock files. You typically need to use an embedded Office Script to unprotect the sheet temporarily, provided the script is authorized to run.




