Search code examples
pythondjangoxlsxwriterdjango-excel

Changing border of group of cells in excell to thick box border with xlsxwriter


I am trying to change box border of some excell cells to "Thick Box Border". I am using django 1.9.5 and python 2.7.5 and xlsxwriter for excell.

import xlsxwriter

workbook = xlsxwriter.Workbook('bordertest.xlsx')
worksheet = workbook.add_worksheet()
format = workbook.add_format({'border': 2})
worksheet.write('B3', 'Border2', format)

This is working for one cell. But i want to apply thick box border around some group of cells like below. I couldn't figure it out. I want to apply thick border to rectangle block of cells between B4-G4 & B8-G8. Between red dots the lines will be bold. But cells in the red dotted rectangle area, will be normal border. So different color group of cells will be seperated with thick border.

enter image description here


Solution

  • Have you tried to loop through it somehow?

    As far as I know conditional formatting gives you the ability to use cell ranges:

    worksheet.conditional_format(cells_range, {'type': 'cell',
                                     'criteria': '=',
                                     'value': 'border2', 'format': format})