ABHI
unread,Aug 29, 2025, 7:26:09 AM (9 days ago) Aug 29Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to openpyxl-users
import openpyxl
from openpyxl.styles import PatternFill, Font, Alignment, Border, Side
from openpyxl.utils import get_column_letter
# Create workbook
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "Team Rating"
# Headers
headers = ["Abhijin", "Amal", "Sruthy", "Sarath"]
ws.append(headers)
# Data (like your sketch)
data = [
[1, "", "", ""],
["", 1, "", ""],
["", "", 1, ""],
["", "", "", 1]
]
for row in data:
ws.append(row)
# Header style
header_fill = PatternFill(start_color="FFD966", end_color="FFD966", fill_type="solid")
header_font = Font(bold=True, color="000000")
for col_num, header in enumerate(headers, 1):
cell = ws.cell(row=1, column=col_num)
cell.fill = header_fill
cell.font = header_font
cell.alignment = Alignment(horizontal="center", vertical="center")
# Data cell style
highlight_fill = PatternFill(start_color="E2EFDA", end_color="E2EFDA", fill_type="solid")
for row in ws.iter_rows(min_row=2, max_row=5, min_col=1, max_col=4):
for cell in row:
cell.alignment = Alignment(horizontal="center", vertical="center")
if cell.value == 1:
cell.fill = highlight_fill
cell.font = Font(bold=True)
# Borders
thin = Side(border_style="thin", color="000000")
border = Border(left=thin, right=thin, top=thin, bottom=thin)
for row in ws.iter_rows(min_row=1, max_row=5, min_col=1, max_col=4):
for cell in row:
cell.border = border
# Adjust width
for col in range(1, 5):
ws.column_dimensions[get_column_letter(col)].width = 15
# Save
wb.save("Team_Rating.xlsx")
print("✅ Excel file 'Team_Rating.xlsx' created successfully!")