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?
解决方案
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