Search code examples
pythonexceldataframexlsxwriter

Changing Format in XLSX file created using XlsxWriter module


I'm trying to change the format in an excel file that has been created using the XlsxWriter module in Python, but so far I haven´t been able to do it. Whenever I open the file in Excel and try to change the border formats nothing happens.

The code I´m using is doing what it is supposed to:

#Test Sheet
    
    #Format
    _format = workbook.add_format({'top':True, 'bottom': True, 'right': True, 'left': True})
    
    _era.to_excel(writer, sheet_name='Test', header=False, index=False, startcol = 2, startrow = 2)
    
    workbook = writer.book
    worksheet = writer.sheets['Test']
    worksheet.hide_gridlines(2)
    worksheet.conditional_format(2, 2, 20, 11, {'type': 'no_blanks', 'format': _format})

The Output:

enter image description here

But afterwards, when I try to change the cell borders format in Excel, nothing happens, it stays the same:

enter image description here

enter image description here

And the result is the exact same thing I downloaded in the first place: enter image description here

I've tried lots of things, but I must be missing something regarding the code I´m using, is there somebody willing to help?

Cheers.


Solution

  • The reason this is happening is because the data grid is being formatted with a conditional format and that overrides any manual border format that is later applied to the cells.

    This isn't related to XlsxWriter. It would also happen with a file created in Excel.