Get number of sheet excel in python

不想你离开。 提交于 2019-12-06 08:10:20

问题


How get number of sheet in below python example?

file = self.excel_file.decode('base64')

excel_fileobj = TemporaryFile('wb+')
excel_fileobj.write(file)
excel_fileobj.seek(0)

workbook = openpyxl.load_workbook(excel_fileobj, data_only=True)

sheet_number= ???

sheet = workbook[workbook.get_sheet_names()[0]]


for row in sheet.rows:
            print(row[1].value)

sheet_number=????

Any solutin?


回答1:


workbook.worksheets contains a list of worksheet objects.

To get the number of worksheets:

sheet_number = len(workbook.worksheets)

Simplest way to iterate over all worksheets:

for ws in workbook.worksheets:
    print ws.title


来源:https://stackoverflow.com/questions/45295580/get-number-of-sheet-excel-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!