Open an excel worksheet with password protection

Saw nice slack reply from @mika and wanted to share also to here.
So if you want only to open password protected excel and retrieve its data for processing you can do it by following steps:

  1. Adjust your conda.yaml to this content:
# For more details on the format and content:
# Tip: Adding a link to the release notes of the packages helps maintenance and security.

  - conda-forge

  # Define conda-forge packages here ->
  # When available, prefer the conda-forge packages over pip as installations are more efficient.
  - python=3.9.13               # 
  - pip=22.1.2                  #
  - msoffcrypto-tool=5.0.1      # 
  - pip:
      # Define pip packages here ->
      - rpaframework==22.5.3    #
  1. Create new file and name it with following content:
import msoffcrypto

def decrypt_office_file(filename: str, password: str, decrypted_filename: str):
    Opens given password proteced excel file
    And saves as new unprotected copy
    with open(filename, "rb") as officein:
        file = msoffcrypto.OfficeFile(officein)
        with open(decrypted_filename, "wb") as f:

  1. Adjust tasks.robot to look like
*** Settings ***
Library     RPA.Excel.Files
Library  #import for our helper function

*** Variables ***
${PASSWORD}     mark    #password for protected file

*** Tasks ***
Decrypt Excel File
    Decrypt Office File    protected.xlsx    ${PASSWORD}    decrypted.xlsx
    Open Workbook    decrypted.xlsx    # Open unprotected copy
    Set cell value    1    1    modified    # write some test values
    Save Workbook        # save changes
    Log    Done.
1 Like