Cannot load workbook

Issue #319 resolved
wlasowne
created an issue

When i try to load workbook, i'm catch the exception

"__init__() got an unexpected keyword argument 'vertAlign'"

the issue in situation where /usr/local/lib/python2.7/dist-packages/openpyxl/reader/style.py in read_style_table try to read

 "<font><vertAlign val="superscript"/><sz val="10"/><color indexed="8"/><name val="Times New Roman"/><family val="1"/><charset val="204"/></font>" 

in styles.xml

Comments (23)

  1. CharlieC

    Thanks for the report and sorry for the error. Support for styles is better in 2.0 but we missed that and it wasn't caught in any tests because we don't have any examples. Do you happen to have a sample file we could use?

  2. CharlieC

    Looks like we drop the following number format:

    <numFmt numFmtId="43" formatCode="_-* #,##0.00_р_._-;\-* #,##0.00_р_._-;_-* "-"??_р_._-;_-@_-"/> Not sure if I want to try and support it! :-)

  3. Eric Gazoni

    it looks like a localized accounting format, but it's built-in. That's the typical issue we might land in: every localized version of Excel will have a different format number 43, following its regional rules, so there is no way we can "support" it without discriminating users not using this locale ...

    For me for instance, it is _ * #.##0,00_) _€_ ;_ * (#.##0,00) _€_ ;_ * "-"??_) _€_ ;_ @_

  4. CharlieC

    @Eric Gazoni I have a fix for reading these files in place but I've hit a bug in styles when it comes to writing relevant tests (preservation of some of the attributes). I think this is down to the some of the signature inspection stuff.

    from openpyxl.styles import Font
    from openpyxl.styles import Style
    st1 = Style()
    ft = Font(name='Calibri', charset=204, vertAlign='superscript')
    ft
    
    ft.vertAlign
    'superscript'
    st2 = Style(font=ft)
    st1 == st2
    True
    ft = Font(name='Calibri', charset=204, vertAlign='superscript', b=True)
    st3 = Style(font=ft)
    st1 == st3
    False
    

    As things stand, fonts with additional values may be counted as the Default and, therefore, not serialised.

  5. CharlieC

    @wlasnowe If you can try the 2.0 branch you should be able to read your file okay. As noted in the discussion here, it doesn't quite save properly.

  6. CharlieC

    Just check out the project into a virtualenv with Mercurial as explained on the site, Something like this on unix style systems. Ask a grown-up for help if you're on Windows! ;-)

    hg clone https://bitbucket.org/ericgazoni 
    cd openpyxl
    hg up 2.0
    virtualenv .
    source bin/activate
    python setup.py develop
    
  7. wlasowne reporter

    Nope. The problem is not resolve... You didn't add "vertAlign" in fonts.py

    P.S.: in fonts.py there are some strange string schema = String(allow_none=True) but in def init there are "scheme"

  8. CharlieC

    Good to hear it's working from you. When I was looking at the file that had passed through openpyxl it didn't look perfect but it looked okay. Looks like we can now preserve most of the formatting.

  9. Log in to comment