How to read Excel files from a stream (not a disk-backed file) in Python?

后端 未结 4 2265
说谎
说谎 2021-02-19 16:59

XLRD is installed and tested:

>>> import xlrd
>>> workbook = xlrd.open_workbook(\'Sample.xls\')

When I read the file through

4条回答
  •  野的像风
    2021-02-19 17:40

    You could try something like...

    import xlrd
    
    def newopen(fileobject, modes):
        return fileobject
    
    oldopen = __builtins__.open
    __builtins__.open = newopen
    InputWorkBook = xlrd.open_workbook(fileobject)
    __builtins__.open = oldopen
    

    You may have to wrap the fileobject in StringIO if it isn't already a file handle.

提交回复
热议问题