# Importing the necessary libraries
from openpyxl import load_workbook
from openpyxl.styles import numbers
# Filename of the Excel file
filename = 'path/to/your/file.xlsx'
# Name of the sheet containing the dates
sheet_name = 'Sheet1'
# Load the workbook
workbook = load_workbook(filename)
# Select the desired sheet
sheet = workbook[sheet_name]
# Iterate through the cells in the desired range
for row in sheet.iter_rows(min_row=1, min_col=1, max_row=sheet.max_row, max_col=sheet.max_column):
for cell in row:
# Check if the cell value is a date or datetime
if cell.data_type == 'd' or cell.data_type == 'n':
cell.number_format = numbers.FORMAT_DATE_DDMMYYYY # Change the date format to your desired format
# Save the modified workbook
workbook.save('path/to/your/modified_file.xlsx')