Formatting to show dollars

2,081 views
Skip to first unread message

Birrell Walsh

unread,
Nov 10, 2015, 4:30:47 PM11/10/15
to openpyxl-users
I was not able to find this (yet) in the documentation.  I need to format column B and cell F1 so the numbers in them are shown in US dollar format - with a leading "$" and two decimal places.

May I ask how to do it?

Thanks

Birrell Walsh

unread,
Nov 10, 2015, 7:05:52 PM11/10/15
to openpyxl-users
I think I could figure out how to put a string in each needed Column B spot, and in F1.  But I would like to leave the underlying floating-point number there and have Excel format it for me, if possible.


Charlie Clark

unread,
Nov 11, 2015, 3:21:03 AM11/11/15
to openpyx...@googlegroups.com
Am .11.2015, 22:30 Uhr, schrieb Birrell Walsh <birrel...@gmail.com>:

> I was not able to find this (yet) in the documentation. I need to format
> column B and cell F1 so the numbers in them are shown in US dollar
> format - with a leading "$" and two decimal places.

It's not specifically covered in the documentation because it's covered by
the specification §18.8.30. openpyxl will just pass the number format
through.

You probably want something like "[$$]##,#0.00" depending on whether you
want a thousands separator and decimal point.

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226

ran.sc...@gmail.com

unread,
Nov 11, 2015, 9:31:52 AM11/11/15
to openpyxl-users
You should work with the number format

an example that works for me:
Sheet_Object.ws['F1'].number_format = u'"$ "#,##0.00'

Birrell Walsh

unread,
Nov 13, 2015, 5:09:48 PM11/13/15
to openpyx...@googlegroups.com
Not sure what "the specification" is, though I would like to know.  I appreciate the help!

Birrell

--
You received this message because you are subscribed to a topic in the Google Groups "openpyxl-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openpyxl-users/chmsMKo550Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openpyxl-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Charlie Clark

unread,
Nov 14, 2015, 8:00:01 AM11/14/15
to openpyx...@googlegroups.com
Am .11.2015, 23:09 Uhr, schrieb Birrell Walsh <bir...@well.com>:

> Not sure what "the specification" is, though I would like to know. I
> appreciate the help!

Under protest Microsoft released the specification ex post facto for
Office 2007 into the public domain as ECMA 376:
http://www.ecma-international.org/publications/standards/Ecma-376.htm

We're on the 4th edition and Part 1 - File Formats and Markup Reference is
the interesting part. Thrilling. No, really.

Birrell Walsh

unread,
Nov 14, 2015, 11:50:16 AM11/14/15
to openpyx...@googlegroups.com
Oh, now that could be useful.  More and more things are using Excel as a midpoint - for instance the (free!) webscraper kimono:


and knowing these codes and having openpyxl, one can use python in that marketplace.  

Thank you for this, and thank you to everyone who has made openpyxl possible.

Birrell

Reply all
Reply to author
Forward
0 new messages