Set openpyxl cell format to currency
Asked Answered
M

2

13

I'm creating an excel sheet using openpyxl. Some cells represent monetary values. How can I change the format of a cell to be of type "currency", i.e. I want a "€" symbol to be displayed after the number.

Musket answered 7/1, 2016 at 10:5 Comment(2)
why not save it as unicode string?Spoken
actually, this was the workaround I'm using at the moment. However, I feel it is cleaner to add the semantic information to the cell, that I could still use it for calculation in excel if needed.Musket
B
27

Try setting the format code with your desired format code

_cell.number_format = '#,##0.00€' 
Beatup answered 7/1, 2016 at 10:15 Comment(4)
your code didn't work for me out of the box, but it guided me to the solution. _cell.number_format = '#,##0.00€' did the trick. Thank you!Musket
That was the older API. We changed in recent versions to make it simpler to use.Jasik
@Musket where exactly is the difference between your code and the accepted answer?Samathasamau
@Samathasamau There is no difference. There was a difference before the edit.Madwort
W
0

Also, if you have any problem using other than 4 currencies mention on here you can also put your currencies according to excel

example:

Russian Ruble: ₽ #,##0.00

Indonesian Rupiah Rp #,##0.00

this is based on @absolutelyNoWarranty answer

Workday answered 12/10, 2023 at 14:25 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.