pythonxlrdxlwtcstringio

Convert cStringIO variable into file


I have an Excel file created inside a cStringIO variable.

I need to open it and read it. But to open an excel file with the xlrd function xlrd.open_workbook(excel_file_name), I need to call it by its file name. But in this case there is no file name because it is a cStrinIO variable that contains the representation of the Excel file.

How can I convert the cStringIO variable into a real excel file that I can open?

Thank you!


Solution

  • Looks like xlrd.open_workbook() accepts file_contents argument as well, so maybe as follows?

    xlrd.open_workbook(file_contents=cstringio_var.getvalue())