从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无关。openpyxl
与3.5设置相比,您在3.6安装中安装了较新的版本。
在3.6中安装的版本已从方法中删除了不推荐使用的坐标参数,worksheet.cell()
并使用row
和column
强制参数。这是2018年1月19日发布的2.5.0b1版本的一部分(两周前):
主要变化
worksheet.cell()
不再接受坐标参数。现在的语法是ws.cell(row, column, value=None)
磁带tablib
库尚未适应此更改。该代码应直接传递列号和行号:
cell = ws.cell(row=row_number, column=col_idx)
使用关键字参数将确保一直到1.1.0(该版本增加了对column
and row
参数的支持的版本,于2010年发行)的兼容性。
同时,您可以将openpyxl
安装降级为版本2.4.9,这是没有这些更改的最新版本。
另请参阅项目存储库中的问题324tablib
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句