Same border side returning different styles

Skip to first unread message

David Tyler

Mar 15, 2023, 11:01:05 AMMar 15
to openpyxl-users
I've noticed that the same borderside object can appear to have a different style depending on the cell in which you're starting. In the attached spreadsheet...
  • wks['C5'])  == 'hair
  • wks['C6']) == 'thin'
Why does this happen? If I can understand this, I can account for it in my code, but I don't have my head around how the same physical border could have two different values. 

I recognize this is not an openpyxl issue -- this has been how borders have worked since at least Excel 97. I never understood the issue when in Excel, but now that I'm "under the hood" more, I need to better account for it. Is there a recommended way to account for this using openpyxl?

Background, general
I'm a teacher and use openpyxl to read in students' Excel submissions. I'm trying to compare the border between an answer key and the student's submission. What I want to do is something like...
anskey_wks['C5']) == stu_wks['C5'])
Instead, I need to add an or statement (or in, any, or something similar) like...
(anskey_wks['C5']) == stu_wks['C5']) or (anskey_wks['C5']) == stu_wks['C6'])

Background, specific
In this specific situation, the cells started off as follows:
  • C5 had a thin top border and a hair bottom border
  • C6 has a hair top border and a hair bottom border
The student copied C5 and pasted it throughout the column, pulling the formatting from C5 and applying it to C6, C7, etc. Thus, C6 ended up with a thin top border (just like C5 started with), and visually that's what we see, but "under the hood" C5 retains its hair bottom border.

Thanks for any suggestions or education you can offer!



Jason Cobble

Mar 19, 2023, 4:15:52 PMMar 19
cause you’re a faggot!

You received this message because you are subscribed to the Google Groups "openpyxl-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web, visit
Reply all
Reply to author
0 new messages