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

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

从 python 3.5 迁移到 3.6,我的单元测试揭示了 django-import-export 和 tablib 的问题:

TypeError:cell() 缺少 1 个必需的位置参数:'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'

tablib 中的行:

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

确实,

列没有参数

我的查看代码:

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

这在 python3.5 中工作正常但在 3.6

下失败

requirements.txt:

...
tablib==0.12.1
django-import-export==0.7.0
Django==1.11.7
...

这与 Python 3.5 或 3.6 无关。与 3.5 安装程序相比,您的 3.6 安装程序安装了更新的 openpyxl 版本。

您安装的3.6版本有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,2018-01-19(两周前)发布:

Major Changes

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

tablib 库尚未适应此更改。代码直接传入列号和行号即可:

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

使用关键字参数将确保一直兼容到 1.1.0(该版本增加了对 columnrow 参数的支持,于 2010 年发布)。

与此同时,您可以将 openpyxl 安装降级到版本 2.4.9,这是没有这些更改的最后一个版本。

另请参阅 tablib 项目存储库中的 issue #324