Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add border to a range of cells using xlsxwriter?

I want to add border around a range of cells like this image1, but my output file looks like this when I applied "set_column" function image2. instead of "set_column", is there any other functions to use?

writer=pd.ExcelWriter('merge_'+name+'.xlsx',
                      engine='xlsxwriter')
workbook  = writer.book
data.to_excel(writer, sheet_name=SheetName,index=False,na_rep=0)
worksheet = writer.sheets[SheetName]
border_format=workbook.add_format({
                            'border':1,
                            'align':'left',
                            'font_size':10
                           })
worksheet.set_column('A:D',12,border_format)

Thank you in advance,

like image 783
talktalk Avatar asked Dec 01 '16 08:12

talktalk


1 Answers

I don't know how with xlsxwriter you can add format at range with set_column or set_row methods, but you can try do it with conditional formatting like this:

worksheet.conditional_format( 'A1:D12' , { 'type' : 'no_blanks' , 'format' : border_format} )

like image 134
Barmaley Avatar answered Nov 15 '22 08:11

Barmaley