import docx
from docx.shared import Pt, Inches, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
doc = docx.Document()
for section in doc.sections:
section.top_margin = Inches(0.8)
section.bottom_margin = Inches(0.8)
section.left_margin = Inches(0.8)
section.right_margin = Inches(0.8)
def set_cell_background(cell, fill_hex):
tcPr = cell._element.get_or_add_tcPr()
shd = OxmlElement('w:shd')
shd.set(qn('w:val'), 'clear')
shd.set(qn('w:color'), 'auto')
shd.set(qn('w:fill'), fill_hex)
tcPr.append(shd)
p_title = doc.add_paragraph()
p_title.alignment = WD_ALIGN_PARAGRAPH.CENTER
r_title = p_title.add_run("REVISED ARRANGEMENT FOR MORNING ASSEMBLY")
r_title.font.name = "Arial"
r_title.font.size = Pt(14)
r_title.font.bold = True
r_title.font.color.rgb = RGBColor(0x1F, 0x4E, 0x78)
p_title.paragraph_format.space_after = Pt(14)
table = doc.add_table(rows=1, cols=2)
table.autofit = False
hdr_cells = table.rows[0].cells
hdr_cells[0].text = "DAY"
hdr_cells[1].text = "ASSEMBLY PROGRAMME DETAILS"
for i in range(2):
set_cell_background(hdr_cells[i], "1F4E78")
p = hdr_cells[i].paragraphs[0]
p.runs[0].font.name = "Arial"
p.runs[0].font.bold = True
p.runs[0].font.color.rgb = RGBColor(0xFF, 0xFF, 0xFF)
p.runs[0].font.size = Pt(11)
if i == 0:
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
col_widths = [Inches(2.0), Inches(4.8)]
data = [
("MONDAY", [
"Prayer- Daya Kar Daan",
"DAV Gaan- Abirala Nirmala",
"Pledge- English",
"National Anthem"
]),
("TUESDAY", [
"Prayer- Itni Shakti",
"Pledge- Hindi",
"National Song- Vande Mataram"
]),
("WEDNESDAY", [
"Prayer- Ki Sundara Aha",
"Pledge- Odia",
"State Anthem- Vande Utkala Janani"
]),
("THURSDAY", [
"Prayer- Manasa Satatam",
"Pledge- Sanskrit",
"Patriotic Song (Sanskrit)- Sarve Saang"
]),
("FRIDAY", [
"Prayer- Ayi Malik Tere Vande Hum",
"Pledge- Hindi",
"Patriotic Song- Sare Jahan Se Acha"
]),
("SATURDAY", [
"1st Week",
"Prayer- Om Hai Jeevan",
"DAV Gaan- Abirala Nirmala",
"Pledge- English",
"National Anthem",
"",
"2nd Week",
"Prayer- Twamewa Maata",
"DAV Gaan- Abirala Nirmala",
"Pledge- English",
"National Anthem",
"",
"3rd Week",
"Prayer- Om Hai Jeevan",
"DAV Gaan- Abirala Nirmala",
"Pledge- English",
"National Anthem",
"",
"4th Week",
"Prayer- Twamewa Maata",
"DAV Gaan- Abirala Nirmala",
"Pledge- English",
"National Anthem"
])
]
for row_idx, (day, lines) in enumerate(data):
row_cells = table.add_row().cells
bg_color = "F2F4F7" if row_idx % 2 == 1 else "FFFFFF"
set_cell_background(row_cells[0], bg_color)
p0 = row_cells[0].paragraphs[0]
p0.alignment = WD_ALIGN_PARAGRAPH.CENTER
r0 = p0.add_run(day)
r0.font.name = "Arial"
r0.font.bold = True
r0.font.size = Pt(10.5)
r0.font.color.rgb = RGBColor(0x1F, 0x4E, 0x78)
p0.paragraph_format.space_before = Pt(6)
p0.paragraph_format.space_after = Pt(6)
set_cell_background(row_cells[1], bg_color)
p1 = row_cells[1].paragraphs[0]
p1.paragraph_format.space_before = Pt(4)
p1.paragraph_format.space_after = Pt(2)
p1.paragraph_format.line_spacing = 1.15
for idx, line in enumerate(lines):
if idx > 0:
p1 = row_cells[1].add_paragraph()
p1.paragraph_format.space_before = Pt(2)
p1.paragraph_format.space_after = Pt(2)
p1.paragraph_format.line_spacing = 1.15
if line in ["1st Week", "2nd Week", "3rd Week", "4th Week"]:
r = p1.add_run(line)
r.font.name = "Arial"
r.font.bold = True
r.font.underline = True
r.font.size = Pt(10.5)
r.font.color.rgb = RGBColor(0x1F, 0x4E, 0x78)
p1.paragraph_format.space_before = Pt(6)
else:
r = p1.add_run(line)
r.font.name = "Arial"
r.font.size = Pt(10)
r.font.color.rgb = RGBColor(0x33, 0x33, 0x33)
for row in table.rows:
for idx, width in enumerate(col_widths):
row.cells[idx].width = width
output_path = "Revised_Arrangement_For_Morning_Assembly.docx"
doc.save(output_path)
print(f"Generated file: {output_path}")
Generated file: Revised_Arrangement_For_Morning_Assembly.docx