Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python xlsxwriter set_indent is not able to do indentation

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

like image 318
ace Avatar asked Dec 19 '25 02:12

ace


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

like image 182
jmcnamara Avatar answered Dec 21 '25 15:12

jmcnamara


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.

like image 24
MattiH Avatar answered Dec 21 '25 16:12

MattiH