decrypted_workbook = io.BytesIO()
with open(file_path, 'rb') as file:
office_file = msoffcrypto.OfficeFile(file)
office_file.load_key(password=password)
office_file.decrypt(decrypted_workbook)
df = pd.read_excel(decrypted_workbook)
I have a password protected xls file which I tried decrypting using msoffcrypto.OfficeFile(). Now when I tried to read the decrypted file, it gives me the following error:
UnicodeDecodeError: 'utf-16-le' codec can't decode bytes in position 52-53: illegal UTF-16 surrogate
I was expecting to read the decrypted file as a workbook. I tried specifying
df = pd.read_excel(decrypted_workbook)
df = pd.read_excel(decrypted_workbook,encoding = "utf-8")
I also tried
df = pd.read_excel(decrypted_workbook, encoding = "utf-16")
None of them worked
Try like this.
If still it does not work, then the file could potentially be corrupted.