BenGoodman
BenGoodman

Reputation: 61

How to choose early / last date in range in openpyxl?

in range (ws) below I have datetimes. I tried hours to print only early / late date but I couldn't. Like min() , max(), if else.. and etc. It has be very simple way I think, but dont know how. How to solve this headache?

from openpyxl import load_workbook
import datetime
wb = load_workbook(filename = 'Test.xlsx')
ws = wb.active

ws1 = ws['B3':'B7']

for i in ws1:    
    for cell in i:
        print (cell.value)

Upvotes: 0

Views: 294

Answers (1)

Charlie Clark
Charlie Clark

Reputation: 19527

You need to extract the values of the cells.

values = [row[0].value for row in ws['B3:B7']]
print(min(values))
print(max(values))

Upvotes: 2

Related Questions