-
-
Notifications
You must be signed in to change notification settings - Fork 595
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: support column_width in xlsx format #516
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #516 +/- ##
==========================================
+ Coverage 90.84% 91.11% +0.27%
==========================================
Files 28 28
Lines 2664 2702 +38
==========================================
+ Hits 2420 2462 +42
+ Misses 244 240 -4 ☔ View full report in Codecov by Sentry. |
Hello @hugovk! Sorry for ping, but I just want to ask if you have any time for review and merge this? |
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.
Thanks for the ping! Please could you add some tests that use the different possible values?
@hugovk Thank you for the review! I've added the test on check the new feature, checkout |
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.
Some general comments. And please could we have three separate test cases that call export_set
with different values for column_width
: None
, an integer and "adaptive"
.
That way we see each branch of your code is running without error, and it will be reflected in the coverage.
Thank you for such usefull comment! I've found a bug with new tests. Your comments are pushed, alongside with all three tests. What do you think on it? |
Thank you for your comment! I believe this significantly improves redability. Could please take a look if the PR is fine now? |
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.
Thank you! A couple of minor suggestions.
Hi there, I would find this enhancement useful. Do you mind to take this last step to add this feature? |
Hi! I won't be able to finish this PR, so feel free to do that! |
Hey! We think it would be useful over at Django-Import-Export! I dont mind picking up this PR (rebasing, docs updates, and your comments @hugovk ) if we think it can be merged in. Given the work put in already by you all, it would be a shame to leave it abandoned. Thanks! |
Sure, feel free to take and polish this PR! |
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>
Okie dokie! I have:
Let me know if there is anything else I can do to get this across the line! Thanks for the help! And sorry for all the force pushes, github didnt like that I was rebasing all the changes of a branch of a fork I dont own 🤷 |
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.
Thanks for refreshing this PR! You may also add an entry in HISTORY.md.
@@ -250,6 +250,19 @@ The ``import_set()`` method also supports a ``skip_lines`` parameter that you | |||
can set to a number of lines that should be skipped before starting to read | |||
data. | |||
|
|||
The ``export_set()`` method supports a ``column_width`` parameter. Depending on the | |||
value passed, the column width will be set accordingly. It can be either ``None``, an integer, or default "adaptive". |
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.
We don't have a linter for the docs, but you may wrap this line in accordance of the rest of the file.
data.export('xlsx', column_width='adaptive') | ||
|
||
|
||
|
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.
I guess one line break would be enough here.
if isinstance(width, str) and width != "adaptive": | ||
msg = ( | ||
f"Invalid value for column_width: {width}. " | ||
f"Must be 'adaptive' or an integer." |
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.
That second line doesn't need the f
prefix.
If ``column_width`` is set to "adaptive", the column width will be set to the maximum | ||
width of the content in each column. If it is set to an integer, the column width will be | ||
set to that integer value. If it is set to None, the column width will be set as the | ||
default openpyxl.Worksheet width value. |
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.
What do you think about accepting a list of column widths to be able to set widths per column? It may also be a follow-up improvement PR.
This PR allows user to specify column width in XLXS format. For it has a default value, which is not suitable for long values in dataset. As a result, it is not convenient to look these tables. Also, it eliminates questions like #318 in future
I didn't find tests for exporting, so omitted this. Let me know if they are required