Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preformat to currency and two decimal places in python using xlwt for excel

Tags:

python

excel

xlwt

I have a column heading Fee. Using xlwt in python, I successfully generated the required excel.This column is always blank at the creation of Excel file.

Is it possible to have the Fee column preformatted to 'Currency' and 'two decimal places', so that when I write manually in the Fee column of the Excel file after downloading, 23 should change into $23.00 ??

like image 382
Abhaya Avatar asked Feb 21 '12 10:02

Abhaya


1 Answers

I got it working like this:

currency_style = xlwt.XFStyle()

currency_style.num_format_str = "[$$-409]#,##0.00;-[$$-409]#,##0.00"

sheet.write(row+2, col, val, style=currency_style)

like image 68
Abhaya Avatar answered Nov 14 '22 23:11

Abhaya