I'm using a software product that is opening and XLS file and sending the XLS as this string
PK\x03\x04\x14\x00\x06\x00\b\x00\x00\x00!\x00{\x92..
I've tried the below code and get the error Unsupported format, or corrupt file: Expected BOF record; found b'<\xac\xc2\xa2{^\x9e\xd4' [file '/home/vflow/.local/lib/python3.6/site-packages/xlrd/book.py', line 1278]
Question is how to open this in xlsx in python when getting this string?
The XLS can be opened using MSoffice. I created a simple xlsx with the word 'test' in on column as a 2nd try. The software we have serves the above string PK... Note the above excel string starts with PK - which indicates a zip file ( xlsx excel files are zipped btw so it looks ok from a byte string point of view.)
Similar question from which the above approach is sourced. Read byte string as xls file
import xlrd
import base64
myvar = data.body # contains : PK\x03\x04\x14\x00\x06\x00\b\x00\x00\x00!\x00{\x92..
decoded_bytes = base64.b64decode(myvar) # contains : <\xac¢{^\x9e\xd4\xf2\xa5\xeb1\x9aY\xf4\x13[PPI\xb2..
x = xlrd.open_workbook(file_contents=decoded_bytes)
# Unsupported format, or corrupt file: Expected BOF record; found b'<\xac\xc2\xa2{^\x9e\xd4' [file '/home/vflow/.local/lib/python3.6/site-packages/xlrd/book.py', line 1278]
x = xlrd.open_workbook(file_contents=data.body) # use data.body instead
# Excel xlsx file; not supported [file '/home/vflow/.local/lib/python3.6/site-packages/xlrd/__init__.py', line 170]