Python xlsxwriter set_indent is not able to do indentation

Viewed 539

I am using a library called xlsxwriter in python for creating a Excel file. I am using 'set_indent' to use indentation before my text in a cell, but i am not sure why it's not working.

Code:-

 workbook = xlsxwriter.Workbook("Example.xlsx")
 worksheet = workbook.add_worksheet("My_Sheet")
 cell_indent_format = workbook.add_format().set_indent(2)
 worksheet.write('B20', "HELLO", cell_indent_format)

Added screenshot

2 Answers

It should work. Just split out the method calls:

import xlsxwriter

workbook = xlsxwriter.Workbook("Example.xlsx")
worksheet = workbook.add_worksheet("My_Sheet")
cell_indent_format = workbook.add_format()
cell_indent_format.set_indent(2)

worksheet.write('B20', "HELLO", cell_indent_format)

workbook.close()

Output:

enter image description here

I thought I had the same issue, but actually my issue was the inability to use this in conditional formatting. In the normal cell formatting it worked though.

Related