[python-win32] Excel "NumberFormat" to Python? (!)

Andrea Gavana andrea.gavana at gmail.com
Fri Aug 5 13:51:18 CEST 2011


Hi All,

    I was wondering if someone had already tackled the problem of converting
Excel cell NumberFormat to something Python can parse and actually use. In
more detail, what I mean is: once you right-click on a cell and select
"Format Cells" you get a huge list of possible formatting options, divided
into categories. I don't think I will have any particular problem in
interpreting and coding in Python what the following NumberFormats mean:

- "0.00"
- "%0.0"
- "General"
- "Text"

But some of them are a bit obscure and problematic to me (in the "Custom"
section):

- "_($* #,##0_);_($* (#,##0);_($* "-"_);"
- "[$€-2] #,##0.00_);[Red]([$€-2] #,##0.00)"

And many others. Not to say anything about all the impossible date formats
(how do I get time.strptime to do the right thing with them?) or the
"Special" and "Fraction" categories. Basically, I know what is the value of
a cell, but I would like to have a string representation of that value as
close as possible as what Excel is showing me on screen, i.e.:

value = 0.154  ==> on-screen: 15.4% (percentage format);
value = 40234.0 ==> on-screen: 2/25/10 12:00 AM (custom date format)

And so on. I would like to get the "on-screen" thing in a Python string. I
know it sounds close to impossible, but maybe someone has an idea or
something similar has already been implemented... I googled back and forth
for this but it seems my google-fu is very weak.

Thank you in advance for your suggestions.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20110805/c06c42e5/attachment.html>


More information about the python-win32 mailing list