Attempting to load a shared protected workbook fails with ValueError: Value does not match pattern [0-9a-fA-F]+$

Issue #1157 resolved
Jeff “Señor Geek” Raber
created an issue

When attempting to load a workbook that is shared and protected with a password required to get read-write access, the below error occurs.

openpyxl.load_workbook('./test.xlsm') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.7/site-packages/openpyxl/reader/excel.py", line 188, in load_workbook parser.parse() File "/usr/lib/python3.7/site-packages/openpyxl/packaging/workbook.py", line 53, in parse package = WorkbookPackage.from_tree(node) File "/usr/lib/python3.7/site-packages/openpyxl/descriptors/serialisable.py", line 84, in from_tree obj = desc.expected_type.from_tree(el) File "/usr/lib/python3.7/site-packages/openpyxl/descriptors/serialisable.py", line 100, in from_tree return cls(**attrib) File "/usr/lib/python3.7/site-packages/openpyxl/workbook/protection.py", line 162, in init self.hashValue = hashValue File "/usr/lib/python3.7/site-packages/openpyxl/descriptors/base.py", line 255, in set raise ValueError('Value does not match pattern {0}'.format(self.pattern)) ValueError: Value does not match pattern [0-9a-fA-F]+$

Inspecting the /xl/workbook.xml file (inside the XLSM/zip) shows that the hashValue and saltValue are not Hexadecimal as indicated in /openpyxl/workbook/protection.py.

Changing the types of FileSharing.hashValue and FileSharing.saltValue to String resolves this issue for me.

Comments (6)

  1. Jeff “Señor Geek” Raber reporter

    Looks like this issue is a duplicate of issue 1055 . Since an example file was request in that issue, I'll attach one here.

    I figured out how to fork this project and have submitted a pull request with the changes I added here yesterday. (I'm new to bitbucket and mercurial, so please let me know if I'm doing something wrong.)

  2. Log in to comment