-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(python): Right-align numerical headers in write_excel
#17877
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17877 +/- ##
=======================================
Coverage 80.48% 80.48%
=======================================
Files 1507 1507
Lines 197610 197619 +9
Branches 2813 2815 +2
=======================================
+ Hits 159040 159051 +11
+ Misses 38049 38046 -3
- Partials 521 522 +1 ☔ View full report in Codecov by Sentry. |
I came searching for an answer to this question and found your issue/PR, I hope you don't mind me contributing some thoughts. I'm not necessarily a fan of using indents automatically if autofilter is applied. It would make things less easy to read in situations like the below: Without IndentWith indentPerhaps better to increase row height so that header text is above the autfilter buttons, rather than use indents to push them to the left? I also think it would be good to add an additional level to your hiearchy to check whether the user has specified an alignment in the Ulitimately, I'd love to give users the ability to format each column of the header themselves individually, similar to how they can with |
@MarkRotchell you're right--column alignment and dtype alignment, if specified, should take precedence over the default logic here of right-alignment. In your screenshot, I agree that in the contrived example the indent doesn't look great. I would bet, though, that in most cases the indentation will look better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ulitimately, I'd love to give users the ability to format each column of the header themselves individually, similar to how they can with column_formats.
@MarkRotchell: I'm also finding it fairly easy to create tables that don't look quite right, so I think I agree with you here 🤔
@mcrumiller I think the way to go is not to change the default, but to extend the header_format
param so that it can do more; specifically, we could support something like {cs.numeric(): {"align": "right"}}
. This would also open up additional formatting possibilities. Can take look at the other params that allow similar capabilities. Want to give it a go? ✌️😎 (apologies for the delay on this review!)
I may be able to get to this this weekend, sorry been busy with real job... I'll close this for now since the new proposal would be a significant deviation in spirit from this PR. It's too bad that Excel chooses to hide text behind the drop-down arrow, otherwise this would be cake to simply apply the column alignment to the header. |
No apologies required, lol... your contributions are always welcome irrespective of time/frequency, etc. It's your free time after all; choosing to spend it helping us out will always be appreciated, so if you want to have another run at it, feel free to do so whenever it works for you! 🫡 |
Resolves #17852.
@alexander-beedie the logic is the following:
autofilter
is enabled, then an indent is applied so that the headers are not hidden.Here is my test to ensure it's working:
Output:
Header with specified alignment. Header should not include new logic.
Header with no specified alignment. Header should right-align with indent.
No header formatting specified. Header should right-align with indent.
No header formatting and autofilter off. Header should right-align without an indent.