Attempting to load a shared protected workbook fails with ValueError: Value does not match pattern [0-9a-fA-F]+$
Created originally on Bitbucket by jraber (Jeff Raber)
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 "", line 1, in 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.
Attachments: openpyxl.workbook.protection.diffopenpyxl.workbook.protection-test.exportopenpyxl.workbook.protection-fix.exportIssue_1157_Example.xlsx