Losing merged cells border while editing Excel file with openpyxl

后端 未结 5 1401
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-09 13:22

I have two sheets in an Excel file and the first one is a cover sheet which I don\'t need to edit. There are a few merged cells in the cover sheet, and when I edit the file usin

5条回答
  •  深忆病人
    2021-02-09 14:21

    Simple method

    1. Go to the folder C:\Python\Lib\site-packages\ openpyxl\worksheet folder\

    2. Open worksheet.py file

    3. In merge_cells function comment the following lines

      min_col, min_row, max_col, max_row = 
         range_boundaries(range_string)
      rows = range(min_row, max_row+1)
      cols = range(min_col, max_col+1)
      cells = product(rows, cols)
      
      all but the top-left cell are removed
      for c in islice(cells, 1, None):
          if c in self._cells:
              del self._cells[c]
      
    4. Save it.

    That's all , it works for me.

提交回复
热议问题