Same border side returning different styles

29 views
Skip to first unread message

David Tyler

unread,
Mar 15, 2023, 11:01:05 AM3/15/23
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']).border.bottom.style  == 'hair
  • wks['C6']).border.top.style == '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']).border.bottom.style == stu_wks['C5']).border.bottom.style
Instead, I need to add an or statement (or in, any, or something similar) like...
(anskey_wks['C5']).border.bottom.style == stu_wks['C5']).border.bottom.style) or (anskey_wks['C5']).border.bottom.style == stu_wks['C6']).border.top.style)

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!

-David

Sample_BorderDiscrepancy.xlsx

Jason Cobble

unread,
Mar 19, 2023, 4:15:52 PM3/19/23
to openpyx...@googlegroups.com
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 openpyxl-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/openpyxl-users/c1bce7d2-f7cc-4b44-8574-9bc98fc3c438n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages