Have you ever wanted to create a checklist or to-do list in Excel that automatically organizes your tasks? With Python, you can automate this process, making it easier to manage your tasks. This automation allows you to add tasks, mark them as complete or incomplete, and even set due dates, all within Excel. Let’s dive in and see how you can create this handy tool to stay organized and on top of your tasks!
To create a todo list or checklist in Excel using Python automation, you can use the openpyxl library.
Let us dive in for fully automated Python code that creates an Excel file with a todo or check list list:
This is how the todolist will look like with drop downs to select

from openpyxl import Workbook
from openpyxl.worksheet.datavalidation import DataValidation
from openpyxl.styles import PatternFill
from datetime import date, timedelta
# Create a new Excel workbook
wb = Workbook()
# Select the active worksheet
ws = wb.active
# Set the title of the todo list
ws.title = "Todo List"
# Add headers
ws["A1"] = "Task"
ws["B1"] = "Status"
ws["C1"] = "Due Date"
# Sample todo list tasks
tasks = ["Complete project report", "Send email to team", "Prepare presentation"]
# Add data validation dropdown for tasks in all rows
for i in range(2, len(tasks) + 2):
dv_task = DataValidation(type="list", formula1=f'"{",".join(tasks)}"', allow_blank=False)
ws.add_data_validation(dv_task)
dv_task.add(ws[f"A{i}"])
# Add data validation dropdown for status in all rows
for i in range(2, len(tasks) + 2):
dv_status = DataValidation(type="list", formula1='"Complete,Incomplete"', allow_blank=False)
ws.add_data_validation(dv_status)
dv_status.add(ws[f"B{i}"])
# Apply conditional formatting for alternating rows
for i in range(2, len(tasks) + 2):
if i % 2 == 0:
for j in range(1, 4):
ws.cell(row=i, column=j).fill = PatternFill(start_color="FFCCCB", end_color="FFCCCB", fill_type="solid")
# Save the Excel file
file_path = "todo_list.xlsx"
wb.save(filename=file_path)
print(f"Todo list saved to {file_path}")
Output:
You can add as many rows you want and as many tasks you want. Just dont forget to change them in the code above
Explanation of the above code:
from openpyxl import Workbook: This line imports a tool called Workbook from a library called openpyxl, which helps us create and manipulate Excel files.from openpyxl.worksheet.datavalidation import DataValidation: This line imports another tool called DataValidation from the openpyxl library, which allows us to add dropdown lists to cells in Excel.from openpyxl.styles import PatternFill: This line imports PatternFill from openpyxl.styles, which helps us apply colors and patterns to cells in Excel.from datetime import date, timedelta: This line imports date and timedelta from the datetime library, which helps us work with dates and time durations in Python.wb = Workbook(): This line creates a new Excel workbook, which is like a blank spreadsheet where we can store our data.ws = wb.active: This line selects the active worksheet in the workbook, which is where we’ll be adding our todo list.ws.title = "Todo List": This line sets the title of the worksheet to “Todo List”, which will appear at the bottom of the Excel window.ws["A1"] = "Task": This line adds the header “Task” to cell A1 in the worksheet, indicating that this column will contain the tasks in our todo list.ws["B1"] = "Status": This line adds the header “Status” to cell B1, indicating that this column will contain the status (complete or incomplete) of each task.ws["C1"] = "Due Date": This line adds the header “Due Date” to cell C1, indicating that this column will contain the due dates for each task.tasks = ["Complete project report", "Send email to team", "Prepare presentation"]: This line creates a list of sample tasks that will be used to populate the dropdown list for the “Task” column.for i in range(2, len(tasks) + 2):: This line starts a loop that iterates over the sample tasks, starting from the second row of the worksheet.dv_task = DataValidation(type="list", formula1=f'"{",".join(tasks)}"', allow_blank=False): This line creates a data validation object that specifies a dropdown list for the current task cell, using the sample tasks list.ws.add_data_validation(dv_task): This line adds the data validation object to the worksheet, which creates the dropdown list for the current task cell.dv_task.add(ws[f"A{i}"]): This line specifies that the dropdown list should be added to the current task cell in the “Task” column.- The next two loops and lines of code (lines 14-17 and 18-21) do the same thing as lines 13-15 but for the “Status” column. They create a dropdown list with options “Complete” and “Incomplete” for each status cell in the “Status” column.
- The next loop and lines of code (lines 22-25) apply conditional formatting to alternate rows in the worksheet, giving them a light-colored background. This makes it easier to read the todo list.
file_path = "todo_list.xlsx": This line specifies the file path where the Excel file will be saved.wb.save(filename=file_path): This line saves the Excel file to the specified file path.print(f"Todo list saved to {file_path}"): This line prints a message to the console indicating that the todo list has been saved successfully.
Note: You can make your to list look more attractive with additions such as header , border, color etc and all these can be achieved without touching the excel sheet just with python code.
To add borders to Excel rows and columns using Python automation with the openpyxl library, you can use the openpyxl.styles.Border class. Here’s an example of how to add borders to rows and columns:
from openpyxl import Workbook
from openpyxl.styles import Border, Side
# Create a new Excel workbook
wb = Workbook()
# Select the active worksheet
ws = wb.active
# Add some data to the worksheet
for row in ws.iter_rows(min_row=1, max_row=5, min_col=1, max_col=5):
for cell in row:
cell.value = "Data"
# Add borders to rows
for row in ws.iter_rows(min_row=1, max_row=5, min_col=1, max_col=5):
for cell in row:
cell.border = Border(top=Side(style='thin'),
left=Side(style='thin'),
right=Side(style='thin'),
bottom=Side(style='thin'))
# Add borders to columns
for col in ws.iter_cols(min_row=1, max_row=5, min_col=1, max_col=5):
for cell in col:
cell.border = Border(top=Side(style='thin'),
left=Side(style='thin'),
right=Side(style='thin'),
bottom=Side(style='thin'))
# Save the Excel file
file_path = "border_example.xlsx"
wb.save(filename=file_path)
print(f"Excel file with borders saved to {file_path}")
Creating a to-do list or checklist in Excel using Python automation offers a convenient way to organize tasks. By automating this process, you can easily add, update, and track your tasks in a structured manner. The source code provided demonstrates how to create such a to-do list, including features like dropdown menus for task selection and status, as well as conditional formatting for better visualization. This automation can help you stay organized and manage your tasks more efficiently, ultimately saving you time and effort.





Leave a Reply