xlsx writer - How to get a thick border on only 1 side of a cell?

I'm writing some pandas dataframes to an excel file. I was wondering if it's possible to write a format to have just a thick right border for example. I tried the below:

 center_thick_rborder = workbook.add_format({'align' : 'center',
                                             'right' : True,

but it just applied a thick border to every border in the column, where I only want the right border. Is this possible? If so, how?

I've seen this question which is where I got the 'border':5 bit from in the above code. I've also seem this question which didn't help me.

1 answer

  • answered 2021-09-23 14:31 jmcnamara

    You need to set the border thickness for the right property, like this:

    import xlsxwriter
    workbook = xlsxwriter.Workbook('test.xlsx')
    worksheet = workbook.add_worksheet()
    center_thick_rborder = workbook.add_format({'align': 'center',
                                                'right': 5})
    worksheet.write(1, 1, 'foo', center_thick_rborder)
    worksheet.write(2, 1, 'bar', center_thick_rborder)
    worksheet.write(3, 1, 'baz', center_thick_rborder)


    enter image description here

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum