您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“Python openpyxl 無法保存文件的情況如何解決”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
使用openpyxl保存文件的時(shí)候,出現(xiàn)最下面異常,查看openpyxl 的版本是2.5.14, 把openpyxl降級(jí)就可以解決此問題。
[root@billig mytest]# pip install openpyxl==2.5.11 DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. Looking in indexes: http://mirrors.aliyun.com/pypi/simple/ Collecting openpyxl==2.5.11 Downloading http://mirrors.aliyun.com/pypi/packages/38/7f/65d6b1700470749579b1585bbaf85fb8885f10fd53a77fb11915df913bbc/openpyxl-2.5.11.tar.gz (173kB) 100% |################################| 174kB 596kB/s Requirement already satisfied: jdcal in /usr/lib/python2.7/site-packages (from openpyxl==2.5.11) (1.4) Requirement already satisfied: et_xmlfile in /usr/lib/python2.7/site-packages (from openpyxl==2.5.11) (1.0.1) Installing collected packages: openpyxl Found existing installation: openpyxl 2.5.14 Uninstalling openpyxl-2.5.14: Successfully uninstalled openpyxl-2.5.14 Running setup.py install for openpyxl ... done Successfully installed openpyxl-2.5.11
raceback (most recent call last): File "excelwritedemonopd.py", line 24, in <module> work_book.save("demo_new.xlsx") File "/usr/lib/python2.7/site-packages/openpyxl/workbook/workbook.py", line 391, in save save_workbook(self, filename) File "/usr/lib/python2.7/site-packages/openpyxl/writer/excel.py", line 284, in save_workbook writer.save(filename) File "/usr/lib/python2.7/site-packages/openpyxl/writer/excel.py", line 266, in save self.write_data() File "/usr/lib/python2.7/site-packages/openpyxl/writer/excel.py", line 85, in write_data self._write_images() File "/usr/lib/python2.7/site-packages/openpyxl/writer/excel.py", line 122, in _write_images self._archive.writestr(img.path[1:], img._data()) File "/usr/lib/python2.7/site-packages/openpyxl/drawing/image.py", line 64, in _data img = _import_image(self.ref) File "/usr/lib/python2.7/site-packages/openpyxl/drawing/image.py", line 33, in _import_image img = PILImage.open(img) File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 2638, in open fp.seek(0) ValueError: I/O operation on closed file.
補(bǔ)充:python的openpyxl 3.0.2版無法保存數(shù)據(jù)
在使用openpyxl3.0.2版的時(shí)候老是
報(bào)錯(cuò)“TypeError: got invalid input value of type , expected string or Element”
在將3.0.2版的卸載并且重新安裝了3.0.0版的openpyxl之后此報(bào)錯(cuò)解除!
“Python openpyxl 無法保存文件的情況如何解決”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。