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

ε祈祈猫儿з 提交于 2021-02-07 07:48:10

问题


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 ??


回答1:


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)



来源:https://stackoverflow.com/questions/9375637/preformat-to-currency-and-two-decimal-places-in-python-using-xlwt-for-excel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!