Menu ▾ ▴

#9 Can't set fixed-point num formats

open-fixed
nobody
None
1
2005-06-30
2005-02-15
No

You can't set fixed point num_format entries (i.e. num_format="0.000")
because this looks to Workbook._save_all_num_formats() like a format
index.

The following fix seems to work (beware whitespace cut-n-paste)

--- Workbook.py.DIST 2004-08-20 09:16:16.000000000 +1000
+++ Workbook.py 2005-02-15 13:44:36.073001000 +1100
@@ -477,7 +477,7 @@
# Check if num_format is an index to a built-in format.
# Also check for a string of zeros, which is a valid format string
# but would evaluate to zero.
- if not re.match(r"^0+\d", num_format):
+ if not re.match(r"^0+[\d\.]", num_format):
if re.match(r"^\d+", num_format):
continue
if num_formats.has_key(num_format):

Discussion

  • Nobody/Anonymous

    Logged In: NO

    Hello, Gregory

    Are you sure? Could you send example where this behaviour is
    not working?

    It's working well:
    nf = wb.add_format(num_format="0.000")
    ws.write([0,0], 3, nf)

    Result: 3,000

    BR EvgenyBF

     
  • Evgeny Filatov

    Evgeny Filatov - 2005-04-25
    • priority: 5 --> 1
     
  • Gregory Bond

    Gregory Bond - 2005-06-30

    test program to show this bug

     
  • Gregory Bond

    Gregory Bond - 2005-06-30

    Logged In: YES
    user_id=293157

    yep i'm sure. test program attached, and I'll add 2 produced XLS files - one before
    the bugfix, one after.

    The one before shows "1.234568" and the Format->Cells shows "General". The
    one after shows "1.2346" and Format->Cells shows "Number" with decimal
    places = 4.

     
  • Gregory Bond

    Gregory Bond - 2005-06-30

    Logged In: YES
    user_id=293157

    [ps: sorry for the delay, only just got back to this]

     
  • Gregory Bond

    Gregory Bond - 2005-06-30

    Output showing the bug

     
  • Evgeny Filatov

    Evgeny Filatov - 2005-06-30

    Logged In: YES
    user_id=952405

    Ohhh... when I was writing answer, I found mistake: Your
    version is incorrect (old)
    if re.match(r"^\d+", num_format):
    continue
    It must be
    if re.match(r"^\d+$", num_format):
    continue
    So, all natural numbers are matched as built-in format
    number. Alexey Morozov fixed it on Aug 27 :)

    Revision 1.29
    Fri Aug 27 14:44:32 2004 UTC (10 months ago) by morozov
    Branch: MAIN

    typo fix in _store_all_num_formats (sync w/ S::WE

    Please, get the last version from CVS.

     
  • Evgeny Filatov

    Evgeny Filatov - 2005-06-30
    • status: open --> open-fixed
     

Log in to post a comment.