0
votes

I want to create an excel sheet which shows the subject title and pass percentage of students in that subject.As the name of the subject is big so I changed the width of the column.I've merged two cells two include the subject name.the first column is surronded by borders around all sides.but the merged coumn do not have any borderd,

can You please help me with this problem?

from openpyxl import *
from openpyxl.styles import NamedStyle,colors,Alignment,Font,PatternFill,Border,Side
wb=Workbook()
report=wb.active
iter=0
#define the style

rows(min_row=3,max_row=1000,min_col=8,max_col=11):

    inner_iter=1

    for cell in row:

        if inner_iter==1:

            cell.value=iter+1

        elif inner_iter==2:

            cell.value="Subject Name"
            report.merge_cells(start_row=3+iter,end_row=3+iter,start_column=9,end_column=10)

        if inner_iter==4:
            cell.value="Percentage"

        cell.style=heading_style

        inner_iter+=1

    iter+=1
wb.save(r"c:\users\lenovo\desktop\haii.xlsx")
1

1 Answers

0
votes

You can set cell's border like this.

from openpyxl.styles.borders import Border
thin_border = Border(left=Side(style='thin'), 
    right=Side(style='thin'), 
    top=Side(style='thin'), 
    bottom=Side(style='thin'))
cell.border = thin_border