I need an easy way to set border around multiple cells, like so:
All I found was border of
The current solution by @aubaub draws an empty box. I needed to draw a frame around existing values without overriding them. This is my function in case it helps anyone:
def draw_frame_border(workbook, worksheet, first_row, first_col, rows_count, cols_count):
# top left corner
worksheet.conditional_format(first_row, first_col,
first_row, first_col,
{'type': 'formula', 'criteria': 'True',
'format': workbook.add_format({'top': 1, 'left': 1})})
# top right corner
worksheet.conditional_format(first_row, first_col + cols_count - 1,
first_row, first_col + cols_count - 1,
{'type': 'formula', 'criteria': 'True',
'format': workbook.add_format({'top': 1, 'right': 1})})
# bottom left corner
worksheet.conditional_format(first_row + rows_count - 1, first_col,
first_row + rows_count - 1, first_col,
{'type': 'formula', 'criteria': 'True',
'format': workbook.add_format({'bottom': 1, 'left': 1})})
# bottom right corner
worksheet.conditional_format(first_row + rows_count - 1, first_col + cols_count - 1,
first_row + rows_count - 1, first_col + cols_count - 1,
{'type': 'formula', 'criteria': 'True',
'format': workbook.add_format({'bottom': 1, 'right': 1})})
# top
worksheet.conditional_format(first_row, first_col + 1,
first_row, first_col + cols_count - 2,
{'type': 'formula', 'criteria': 'True', 'format': workbook.add_format({'top': 1})})
# left
worksheet.conditional_format(first_row + 1, first_col,
first_row + rows_count - 2, first_col,
{'type': 'formula', 'criteria': 'True', 'format': workbook.add_format({'left': 1})})
# bottom
worksheet.conditional_format(first_row + rows_count - 1, first_col + 1,
first_row + rows_count - 1, first_col + cols_count - 2,
{'type': 'formula', 'criteria': 'True', 'format': workbook.add_format({'bottom': 1})})
# right
worksheet.conditional_format(first_row + 1, first_col + cols_count - 1,
first_row + rows_count - 2, first_col + cols_count - 1,
{'type': 'formula', 'criteria': 'True', 'format': workbook.add_format({'right': 1})})