Skip to content
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

Merged
merged 21 commits into from
Jan 20, 2025
Merged

Conversation

Birdi7
Copy link
Contributor

@Birdi7 Birdi7 commented Feb 17, 2022

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

@codecov
Copy link

codecov bot commented Feb 17, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.11%. Comparing base (de1a47a) to head (0f7e2ef).
Report is 59 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

@Birdi7 Birdi7 changed the title feat: support column_width in xlxs format feat: support column_width in xlsx format Mar 31, 2022
@Birdi7
Copy link
Contributor Author

Birdi7 commented Mar 31, 2022

Hello @hugovk! Sorry for ping, but I just want to ask if you have any time for review and merge this?

Copy link
Member

@hugovk hugovk left a 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?

docs/formats.rst Outdated Show resolved Hide resolved
@Birdi7
Copy link
Contributor Author

Birdi7 commented Apr 1, 2022

@hugovk Thank you for the review! I've added the test on check the new feature, checkout test_xlsx_column_width. Would you mind review the PR, and if everything is ok merge it to master?

Copy link
Member

@hugovk hugovk left a 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.

AUTHORS Outdated Show resolved Hide resolved
docs/formats.rst Outdated Show resolved Hide resolved
docs/formats.rst Outdated Show resolved Hide resolved
src/tablib/formats/_xlsx.py Outdated Show resolved Hide resolved
src/tablib/formats/_xlsx.py Outdated Show resolved Hide resolved
@Birdi7
Copy link
Contributor Author

Birdi7 commented Apr 1, 2022

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?

tests/test_tablib.py Outdated Show resolved Hide resolved
@Birdi7
Copy link
Contributor Author

Birdi7 commented Jun 8, 2022

Thank you for your comment! I believe this significantly improves redability. Could please take a look if the PR is fine now?

src/tablib/formats/_xlsx.py Outdated Show resolved Hide resolved
Copy link
Member

@hugovk hugovk left a 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.

docs/formats.rst Outdated Show resolved Hide resolved
src/tablib/formats/_xlsx.py Outdated Show resolved Hide resolved
@rakinson
Copy link

Hi there, I would find this enhancement useful. Do you mind to take this last step to add this feature?
Thank you!

@Birdi7
Copy link
Contributor Author

Birdi7 commented Oct 8, 2024

Hi! I won't be able to finish this PR, so feel free to do that!

@andrewgy8
Copy link
Member

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!

@claudep
Copy link
Contributor

claudep commented Jan 17, 2025

Sure, feel free to take and polish this PR!

@andrewgy8
Copy link
Member

andrewgy8 commented Jan 18, 2025

Okie dokie! I have:

  • updated the code with comments from @hugovk
  • rebased on master ✅
  • cleaned up the tests a bit ✅
  • and cleaned up the column width code a bit ✅

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 🤷

Copy link
Contributor

@claudep claudep left a 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.

docs/formats.rst Outdated Show resolved Hide resolved
docs/formats.rst Outdated Show resolved Hide resolved
src/tablib/formats/_xlsx.py Outdated Show resolved Hide resolved
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.
Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that would be a valid iteration on this change 👍

@andrewgy8
Copy link
Member

Updated @claudep ! Thanks for the quick review!

@claudep
Copy link
Contributor

claudep commented Jan 19, 2025

Thanks, let's wait now for @hugovk to make a final review.

docs/formats.rst Outdated Show resolved Hide resolved
src/tablib/formats/_xlsx.py Outdated Show resolved Hide resolved
Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@claudep claudep merged commit b783693 into jazzband:master Jan 20, 2025
19 checks passed
@andrewgy8
Copy link
Member

Thanks all! Looking forward to adding this to Django Import Export!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants