Python openpyxl 无法保存文件的解决方案
使用openpyxl保存文件的时候,出现最下面异常,查看openpyxl的版本是2.5.14,把openpyxl降级就可以解决此问题。
[root@billigmytest]#pipinstallopenpyxl==2.5.11 DEPRECATION:Python2.7willreachtheendofitslifeonJanuary1st,2020.PleaseupgradeyourPythonasPython2.7won'tbemaintainedafterthatdate.AfutureversionofpipwilldropsupportforPython2.7. Lookinginindexes:http://mirrors.aliyun.com/pypi/simple/ Collectingopenpyxl==2.5.11 Downloadinghttp://mirrors.aliyun.com/pypi/packages/38/7f/65d6b1700470749579b1585bbaf85fb8885f10fd53a77fb11915df913bbc/openpyxl-2.5.11.tar.gz(173kB) 100%|################################|174kB596kB/s Requirementalreadysatisfied:jdcalin/usr/lib/python2.7/site-packages(fromopenpyxl==2.5.11)(1.4) Requirementalreadysatisfied:et_xmlfilein/usr/lib/python2.7/site-packages(fromopenpyxl==2.5.11)(1.0.1) Installingcollectedpackages:openpyxl Foundexistinginstallation:openpyxl2.5.14 Uninstallingopenpyxl-2.5.14: Successfullyuninstalledopenpyxl-2.5.14 Runningsetup.pyinstallforopenpyxl...done Successfullyinstalledopenpyxl-2.5.11
raceback(mostrecentcalllast): File"excelwritedemonopd.py",line24,inwork_book.save("demo_new.xlsx") File"/usr/lib/python2.7/site-packages/openpyxl/workbook/workbook.py",line391,insave save_workbook(self,filename) File"/usr/lib/python2.7/site-packages/openpyxl/writer/excel.py",line284,insave_workbook writer.save(filename) File"/usr/lib/python2.7/site-packages/openpyxl/writer/excel.py",line266,insave self.write_data() File"/usr/lib/python2.7/site-packages/openpyxl/writer/excel.py",line85,inwrite_data self._write_images() File"/usr/lib/python2.7/site-packages/openpyxl/writer/excel.py",line122,in_write_images self._archive.writestr(img.path[1:],img._data()) File"/usr/lib/python2.7/site-packages/openpyxl/drawing/image.py",line64,in_data img=_import_image(self.ref) File"/usr/lib/python2.7/site-packages/openpyxl/drawing/image.py",line33,in_import_image img=PILImage.open(img) File"/usr/lib64/python2.7/site-packages/PIL/Image.py",line2638,inopen fp.seek(0) ValueError:I/Ooperationonclosedfile.
补充:python的openpyxl3.0.2版无法保存数据
在使用openpyxl3.0.2版的时候老是
报错“TypeError:gotinvalidinputvalueoftype,expectedstringorElement”
在将3.0.2版的卸载并且重新安装了3.0.0版的openpyxl之后此报错解除!
以上为个人经验,希望能给大家一个参考,也希望大家多多支持毛票票。如有错误或未考虑完全的地方,望不吝赐教。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。