Cell borders lost on save

Issue #1069 resolved
陈伟 created an issue

First of all, please forgive me for my English is not good, but I have encountered problems in using openpyxl, I hope to be resolved.

I have the same problem as [#700] (https://bitbucket.org/openpyxl/openpyxl/issues/700/cell-borders-lost-on-save).

I see your reply is "Duplicate of #365."

#365 solves the solution of creating merged cells using python. Suppose I created an excel file using Miscrosoft Excel, which includes a merged cell with a border. When I edit the file using the python program, I call the save() method, and the original border of the merged cell is lost.

Original: 原文件.png Saved: 生成文件.png

Comments (12)

  1. HarryZhang

    I downloaded 2.6.0-dev code and run python setup.py install,But the problem still existed. Even I wrote nothing to some merged cells ,still lossing right borders. How should I do? bad_1.png bad_2.png

  2. David Wheeler

    Hi Harry,

    I have a version I built with some fixes for this issue in it that I am still using. You are welcome to pull that and see if you like it any better. You will find it at bitbucket repo wheeled/openpyxl.

    I offered this up as a PR for the project, but it was declined.

    Best regards, David

    (

  3. HarryZhang

    Hi David, I have tried your code (V 2.5.4) just now,but no effects. The problem is still existed. Below is my writing one column code:

    def write_one_col(self, sheet, colindex, rowindex_start, rowindex_end, datas, index_start=0):
            while rowindex_start <= rowindex_end and index_start < len(datas):
                sheet.cell(row=rowindex_start, column=colindex, value=datas[index_start])
                rowindex_start += 1
                index_start += 1
            if index_start >= len(datas):
                return True, index_start
            else:
                return False, index_start 
    

    should I write and merge cell at the same time,instead of writing directly to excel template?

  4. CharlieC

    The fix is in the 2.6 branch which hasn't been released yet. You can either use this or a monkey patch but please note that neither method is supported and therefore not advisable in a production environment.

  5. HarryZhang

    @CharlieC, I downloaded your link’s branch code,and run "python setup.py install" command. Now openpyxl version is 2.5.4 in my computer. But Cell Loss Borders is still existed. The experience is so bad. How to fix this bug based on 2.5.8, or whether to wait for 2.6 release version,how long for this version? Best regards.

  6. CharlieC

    @zhangharry Welcome to the world of open source: there are no definite release dates but hopefully some time this year.

  7. Log in to comment