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

Styling merged cells #39

Open
vinraspa opened this issue Oct 4, 2023 · 1 comment
Open

Styling merged cells #39

vinraspa opened this issue Oct 4, 2023 · 1 comment

Comments

@vinraspa
Copy link

vinraspa commented Oct 4, 2023

The example given in the doc:

>>> from openpyxl.styles import Border, Side, PatternFill, Font, GradientFill, Alignment
>>> from openpyxl import Workbook
>>>
>>> wb = Workbook()
>>> ws = wb.active
>>> ws.merge_cells('B2:F4')
>>>
>>> top_left_cell = ws['B2']
>>> top_left_cell.value = "My Cell"
>>>
>>> thin = Side(border_style="thin", color="000000")
>>> double = Side(border_style="double", color="ff0000")
>>>
>>> top_left_cell.border = Border(top=double, left=thin, right=thin, bottom=double)
>>> top_left_cell.alignment = Alignment(horizontal="center", vertical="center")
>>>
>>> wb.save("styled.xlsx")

does not work for bottom and right borders.

image

@id-hkj
Copy link

id-hkj commented Mar 10, 2024

For me, the code works if I move merging the cells to after doing all the styling as shown below:

>>> from openpyxl.styles import Border, Side, PatternFill, Font, GradientFill, Alignment
>>> from openpyxl import Workbook
>>>
>>> wb = Workbook()
>>> ws = wb.active
>̶>̶>̶ ̶w̶s̶.̶m̶e̶r̶g̶e̶_̶c̶e̶l̶l̶s̶(̶'̶B̶2̶:̶F̶4̶'̶)̶
>>>
>>> top_left_cell = ws['B2']
>>> top_left_cell.value = "My Cell"
>>>
>>> thin = Side(border_style="thin", color="000000")
>>> double = Side(border_style="double", color="ff0000")
>>>
>>> top_left_cell.border = Border(top=double, left=thin, right=thin, bottom=double)
>>> top_left_cell.alignment = Alignment(horizontal="center", vertical="center")
>>>
>>> ws.merge_cells('B2:F4')
>>>
>>> wb.save("styled.xlsx")

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

No branches or pull requests

2 participants