Set currency symbol when writing with xlsxwriter

I am having trouble writing the currency symbol I want in my currency values โ€‹โ€‹with xlsxwriter .

I followed the tutorial here , and I can write out currency values โ€‹โ€‹with the correct formatting and dollar sign (either from the lesson or from the excel default settings I'm not sure).

It works:

 money = workbook.add_format({'num_format':'$#,##0.00'}) 

And he prints the value of the currency with a dollar sign.

 $1,000.00 

But if I try to insert my own currency, say R :

 money = workbook.add_format({'num_format':'R#,##0.00'}) 

I get this:

 R1000 

How to set currency symbol using xlsxwriter?

+9
python excel currency number-formatting xlsxwriter
source share
2 answers

Please try:

 num_format('"R" #,##0.00') 

format.set_num_format ()

+6
source share

Try the following:

 import xlsxwriter workbook = xlsxwriter.Workbook('money_format.xlsx') worksheet = workbook.add_worksheet() money_format = workbook.add_format({'num_format': '[$R]#,##0.00'}) worksheet.write('A1', 1234.56, money_format) workbook.close() 

The best way to determine the desired number format is to format the cell in Excel, and then edit it and see what the user format is.

It could be something like [$R-431]#,##0.00 or something rather complicated if positive and negative values โ€‹โ€‹are handled differently.

+2
source share

All Articles