python 3.5 -> 3.6 Tablib TypeError: cell() missing 1 required positional argument: 'column'
Asked Answered
D

1

11

Migrating from python 3.5 to 3.6, my unit tests reveal a problem with django-import-export & tablib:

TypeError: cell() missing 1 required positional argument: 'column'

File "<path>/lib/python3.6/site-packages/tablib/formats/_xlsx.py", line 122, in dset_sheet
    cell = ws.cell('%s%s' % (col_idx, row_number))
    TypeError: cell() missing 1 required positional argument: 'column'

The line in tablib:

    cell = ws.cell('%s%s' % (col_idx, row_number))

So indeed, there is no argument for the column

My view code:

my_resource = MyModelResource(queryset=my_queryset)
dataset = my_resource.export()
response = HttpResponse(dataset.xlsx, content_type='application/vnd.ms-excel')

This works fine in python3.5 but fails under 3.6

requirements.txt:

...
tablib==0.12.1
django-import-export==0.7.0
Django==1.11.7
...
Disoblige answered 3/2, 2018 at 13:50 Comment(0)
L
34

This has nothing to do with Python 3.5 or 3.6. You have a newer openpyxl version installed with your 3.6 installation compared to your 3.5 setup.

The version you have installed with 3.6 has removed the deprecated coordinate parameter from worksheet.cell() method and made the row and column mandatory arguments. This is part of version 2.5.0b1, released on 2018-01-19 (two weeks ago):

Major Changes

worksheet.cell() no longer accepts a coordinate parameter. The syntax is now ws.cell(row, column, value=None)

The tablib library has not yet adjusted to this change. The code should just pass in the column and row numbers directly:

cell = ws.cell(row=row_number, column=col_idx)

Using keyword arguments would ensure compatibility all the way back to 1.1.0 (the release that added support for the column and row parameters, released in 2010).

In the meantime, you can downgrade your openpyxl installation to version 2.4.9, the last release without those changes.

Also see issue #324 in the tablib project repository.

Lombroso answered 3/2, 2018 at 13:59 Comment(2)
Great answer. Adding openpyxl==2.4.9 to the requirements.txt file indeed fixes this issue.Disoblige
Excellent thanks! I hope this is not the beginning of the end for the awesomest tablib package.Pincus

© 2022 - 2024 — McMap. All rights reserved.