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

add set_range_style by a simple way #81

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

Harpsichord1207
Copy link

No description provided.

@kevmo314
Copy link
Collaborator

kevmo314 commented Aug 8, 2019

Thank you for your contribution! For a little more context, what's the motivation for this method instead of requiring the user to explicitly iterate over the range?

@kevmo314 kevmo314 self-requested a review August 8, 2019 09:42
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.7%) to 91.615% when pulling 731ed89 on Harpsichord1207:dev into 70dd88a on kz26:dev.

@Harpsichord1207
Copy link
Author

Harpsichord1207 commented Aug 8, 2019

Thank you for your contribution! For a little more context, what's the motivation for this method instead of requiring the user to explicitly iterate over the range?

Hello, sorry to reply late, in my case, I need to merge some cells, but when i merged them, there 's something wrong with boders, and i found a same issue #74, so i try to write a function to fix it.

Copy link
Collaborator

@kevmo314 kevmo314 left a comment

Choose a reason for hiding this comment

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

Thanks, could you add a test and some examples to the README?

for cell in _range:
r, c = cell.coordinate
if r in margin_row or c in margin_col:
self.set_cell_style(r, c, Style.Style(borders=value._borders))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if this is implemented as users would typically expect. If I set the borders to all four sides and then make a 2x2 range, wouldn't this add borders inside the range as well?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it wouldn't add borders to inner cells, but I found there are some more complicated situations that the function may not support, and I also should consider the funtion complexity. I will try a better way.


the 2x2 range example:

from pyexcelerate import Workbook, Style, Font, Alignment
from pyexcelerate.Border import Border
from pyexcelerate.Borders import Borders

data = [[1, 2, 3], [4, 5, 6], [7, 8, 9], ["a", "b", "c"]]
wb = Workbook()
ws = wb.new_sheet("test", data=data)
style = Style(
    font=Font(bold=True),
    borders=Borders(left=Border(), right=Border(), top=Border(style="double"), bottom=Border(style="double")),
    alignment=Alignment('center', 'center')
)

range = ("B2", "C3")
ws.range(*range).merge()
ws.set_range_style(*range, style)
wb.save("test.xlsx")

image

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.

None yet

3 participants