def box(workbook, sheet_name, row_start, col_start, row_stop, col_stop):
    """Makes an RxC box. Use integers, not the 'A1' format"""
rows = row_stop - row_start + 1
cols = col_stop - col_start + 1
for x in range(rows * cols):
    box_form = workbook.add_format()
row = row_start + x // cols
column = col_start + x % cols
if x < cols:
    box_form = add_to_format(box_form, {'top': 1}, workbook)
if x >= rows * cols - cols:
    box_form = add_to_format(box_form, {'bottom': 1}, workbook)
if x % cols == 0:
    box_form = add_to_format(box_form, {'left': 1}, workbook)
if x % cols == cols - 1:
    box_form = add_to_format(box_form, {'right': 1}, workbook)
sheet_name.write(row, column, '', box_form)
python XlsxWriter устанавливает границу вокруг нескольких ячеек