I have a simple code:
import xlrd
book = xlrd.open_workbook('import.xls')
for sheet in book.sheets():
for row in range(sheet.nrows):
print sheet.row(row)
but it's printing:
sheet1: row1
sheet1: row2
sheet1: row3
sheet2: row1
sheet2: row2
sheet2: row3
and etc
I need to change this code to print this:
sheet1: row1
sheet2: row1
sheet3: row1
sheet1: row2
sheet2: row2
sheet3: row2
and etc.
Any help would be highly appreciated. Thanks
import xlrd
book = xlrd.open_workbook('import.xls')
max_nb_row = 0
for sheet in book.sheets():
max_nb_row = max(max_nb_row, sheet.nrows)
for row in range(max_nb_row) :
for sheet in book.sheets() :
if row < sheet.nrows :
print sheet.row(row)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With