[Python] Apply outline border only to range of cells with openpyxl

Discussão em 'Python' iniciado por Stack, Setembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    I'm looking to apply an outline border to a range of cells using openpyxl.

    I've seen articles describing how to iterate over cells in a range & apply a border to each cell - this is not what I need.

    Below is my code to define the border, but I cannot see how to apply it to a range/selection of cells.

    thickBorder = openpyxl.styles.borders.Border(left=openpyxl.styles.borders.Side(style="thick"),
    right=openpyxl.styles.borders.Side(style="thick"),
    top=openpyxl.styles.borders.Side(style="thick"),
    bottom=openpyxl.styles.borders.Side(style="thick"),
    outline=True
    )


    I've also tried adding a border to a range, but this doesn't work.

    myRange = ws["B4":"Y6"]
    myRange.border = thickBorder


    Any suggestions?

    Continue reading...

Compartilhe esta Página