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.
Asked
Active
Viewed 2.5k times
12
-
why not save it as unicode string? – Vaulstein Jan 07 '16 at 10:10
-
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. – Dominic Jan 07 '16 at 10:20
1 Answers
24
Try setting the format code with your desired format code
_cell.number_format = '#,##0.00€'

Community
- 1
- 1

absolutelyNoWarranty
- 1,888
- 2
- 17
- 17
-
2your 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! – Dominic Jan 07 '16 at 10:36
-
4That was the older API. We changed in recent versions to make it simpler to use. – Charlie Clark Jan 07 '16 at 10:48
-
@Dominic where exactly is the difference between your code and the accepted answer? – Gigino Jan 19 '21 at 08:53
-
1@Gigino There is no difference. There was a difference before the edit. – Mare Seestern Oct 03 '21 at 18:36