openpyxl merged cells: Formatting issue

2020-03-25 07:49发布

Say I have an xlsx-file and this Excel file has cells A2 and B2 merged. I also select that merged cell and put a border at the top and bottom of the merged cell.

original excel file

When I do the following:

wb = openpyxl.load_workbook("file.xlsx")
wb.save("resulting file.xlsx")

The result is that only the portion around the merged cell that is in column A now has the border:

resulting excel file

Is there a way to prevent this from happening?

1条回答
你好瞎i
2楼-- · 2020-03-25 08:28

I believe you are facing Issue#365 , there is generally an issue around styling for merged cells, I believe the above mentioned issues tracks it.

Sadly, I do not see any workaround for this issue, neither is any such workaround mentioned in the issue linked.

Another issue that is more directly related to the one you are facing (it is closed as duplicate of the above mentioned issue) -

Issue#378 - Missing border edges on different cells on open and save existing excel file

查看更多
登录 后发表回答