Applying borders to a cell in OpenPyxl

后端 未结 3 1395
鱼传尺愫
鱼传尺愫 2020-12-29 06:52

I am trying to use Openpyxl to apply a border to a cell, but I have failed on the most basic \"apply any kind of border to any cell anywhere\" task. I tried copying from th

3条回答
  •  灰色年华
    2020-12-29 07:36

    This answer works with version 2.4.8 The difference with the previous two answers is that the property for Side is border_style, not style

    from openpyxl.styles.borders import Border, Side, BORDER_THIN
    thin_border = Border(
        left=Side(border_style=BORDER_THIN, color='00000000'),
        right=Side(border_style=BORDER_THIN, color='00000000'),
        top=Side(border_style=BORDER_THIN, color='00000000'),
        bottom=Side(border_style=BORDER_THIN, color='00000000')
    )
    ws.cell(row=3, column=2).border = thin_border
    

    Working with styles: https://openpyxl.readthedocs.io/en/2.5/styles.html

提交回复
热议问题