How to obtain sheet names from XLS files without loading the whole file?

后端 未结 6 648
独厮守ぢ
独厮守ぢ 2020-11-29 22:36

I\'m currently using pandas to read an Excel file and present its sheet names to the user, so he can select which sheet he would like to use. The problem is that the files a

6条回答
  •  既然无缘
    2020-11-29 23:02

    you can use the xlrd library and open the workbook with the "on_demand=True" flag, so that the sheets won't be loaded automaticaly.

    Than you can retrieve the sheet names in a similar way to pandas:

    import xlrd
    xls = xlrd.open_workbook(r'', on_demand=True)
    print xls.sheet_names() # <- remeber: xlrd sheet_names is a function, not a property
    

提交回复
热议问题