TypeError: __init__() got an unexpected keyword argument 'extLst'

Issue #928 resolved
Raul Padilla created an issue

Hey Charlie,

Openpyxl 2.5.0b1 now works fine for Excel workbooks with only one pivot table. I noticed that if a workbook contains multiple pivot tables, it will get the error below. Please let me know if you have the same issue. Thanks!

TypeError Traceback (most recent call last) <ipython-input-9-7e418d5f0397> in <module>() 23 24 destination = 'C:/Users/raul.padilla/Desktop/SPOTLIGHT ACTUALIZATION TEMPLATE (UPDATED).xlsx'

---> 25 wb = openpyxl.load_workbook(destination) 26 writer = pd.ExcelWriter(destination, engine='openpyxl') 27 writer.book = wb

~\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\reader\excel.py in load_workbook(filename, read_only, keep_vba, data_only, guess_types, keep_links) 280 src = archive.read(pivot_path) 281 tree = fromstring(src) --> 282 pivot = TableDefinition.from_tree(tree) 283 pivot.cache = pivot_caches[pivot.cacheId] 284 ws.add_pivot(pivot)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py in from_tree(cls, node) 77 if hasattr(desc, 'from_tree'): 78 #descriptor manages conversion ---> 79 obj = desc.from_tree(el) 80 else: 81 if hasattr(desc.expected_type, "from_tree"):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\descriptors\sequence.py in from_tree(self, node) 84 85 def from_tree(self, node): ---> 86 return [self.expected_type.from_tree(el) for el in node] 87 88

~\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\descriptors\sequence.py in <listcomp>(.0) 84 85 def from_tree(self, node): ---> 86 return [self.expected_type.from_tree(el) for el in node] 87 88

~\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py in from_tree(cls, node) 97 attrib[tag] = obj 98 ---> 99 return cls(**attrib) 100 101

TypeError: init() got an unexpected keyword argument 'extLst'

Comments (9)

  1. CharlieC

    Thanks for the report. Multiple pivot tables are supported: I tested with files that contain hundreds. The problem here is that something contains a post-specification extension from Microsoft. openpyxl currently handles this by ignoring such extensions but they are initially passed into the classes constructor as keywords. Easy to fix with a sample file.

  2. Raul Padilla reporter

    Hi Charlie,

    Thanks for the quick reply. Attached are two excel files. The excel file destination.xlsx has two worksheets each with a pivot table - 'By Placement' and 'Error Check'. Please let me know how I could fix this to handle multiple pivot tables. Below is the code. Thank you very much.

    import pandas as pd
    from datetime import datetime
    import openpyxl
    df = pd.read_excel('dataframe.xlsx', 'Sheet1')
    destination = 'destination.xlsx'
    wb = openpyxl.load_workbook(destination)
    writer = pd.ExcelWriter(destination, engine='openpyxl') 
    writer.book = wb
    writer.sheets = dict((ws.title, ws) for ws in wb.worksheets)
    df.to_excel(writer, 'Spotlight Report', startrow=4, startcol=0, header=False, index=False)
    ext = datetime.now().strftime('%m.%d.%y_%Hh%Mm%Ss')
    wb.save('RESULT ' + ext + '.xlsx')
  3. CharlieC

    Should work fine with a checkout. And, of course, I suggest you use from openpyxl.utils.dataframe import dataframe_to_rows for fine-grained control.

  4. Raul Padilla reporter

    Hey Charlie. I have been working to resolve this for about a week now and I genuinely cannot figure this out. I tried different ways on adding a keyword parameter for extLst but nothing works. I also can't find the commit that fixes the problem that you were referring to. Any further help/advise is sincerely appreciated. Thanks!

  5. Log in to comment