Is there a way to pass the contents of an Excel file, rather than a file name/reference, to the xlrd module's open_workbook() function? I've been trying to use the "file_contents" parameter for this purpose, but haven't had any success with it so far. Thank you.
@Ber's comment is correct. You will need to use the getvalue() method of the StringIO object and pass that to the file_content parameter in the function call.
f = StringIO.StringIO(content)
book = xlrd.open_workbook(file_contents = f.getvalue() )
In most places where an open file is needed, a StringIO object will also work.
You just cread a StringIO object from the file data and pass that object as the file to your function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With