问题
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