'How to print a specific string on a specific date using openpyxl
I am trying to create a rolling rota using openpyxl. Some staff members work a 4 on 4 off rolling shift and I am trying to print "N/A" on the dates they are not working.
So far I have the following code:
from datetime import date
today = date.today()
I have tried the following code:
if today == "2022-02-21":
sheet["D13"] = "N/A"
This does not seem to print "N/A" in my desired cell.
I hope my query is not too confusing. Any help will be appreciated.
Solution 1:[1]
You have to convert the string to date. probably you will have to iterate over that column and convert it to date, or you can go with the solution offered by mwo.
from datetime import datetime
your_date = '2022-02-21'
date_obj = datetime.strptime(your_date, '%Y-%m-%d')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dmitriy Zub |