概述
代码如下:
import openpyxl as ops
import gc
wb02=ops.load_workbook(“G:/Python/Project/data.xlsx”)
ws01=wb02.worksheets[0]
rows_num=ws01.max_row
cols_num=ws01.max_column
print(rows_num,cols_num)
for i in range (rows_num):
if i==0:
print("")
else:
b=ws01.cell(i,7).value
c=ws01.cell(i,18).value
if “Asia” in b and c is None and “Video” in c:
ws01.cell(i,23,“1”)
wb02.save(“G:/Python/Project/test.xls”)
del wb02,ws01
gc.collect()
报错如下:
Traceback (most recent call last):
File “E:/Program Files/Python/123.py”, line 19, in
wb02.save(“G:/Python/Project/Amcrest.xls”)
File “C:UsersRaytineAppDataLocalProgramsPythonPython38libsite-packagesopenpyxlworkbookworkbook.py”, line 392, in save
save_workbook(self, filename)
File “C:UsersRaytineAppDataLocalProgramsPythonPython38libsite-packagesopenpyxlwriterexcel.py”, line 293, in save_workbook
writer.save()
File “C:UsersRaytineAppDataLocalProgramsPythonPython38libsite-packagesopenpyxlwriterexcel.py”, line 275, in save
self.write_data()
File “C:UsersRaytineAppDataLocalProgramsPythonPython38libsite-packagesopenpyxlwriterexcel.py”, line 75, in write_data
self._write_worksheets()
File “C:UsersRaytineAppDataLocalProgramsPythonPython38libsite-packagesopenpyxlwriterexcel.py”, line 215, in _write_worksheets
self.write_worksheet(ws)
File “C:UsersRaytineAppDataLocalProgramsPythonPython38libsite-packagesopenpyxlwriterexcel.py”, line 200, in write_worksheet
writer.write()
File “C:UsersRaytineAppDataLocalProgramsPythonPython38libsite-packagesopenpyxlworksheet_writer.py”, line 355, in write
self.write_rows()
File “C:UsersRaytineAppDataLocalProgramsPythonPython38libsite-packagesopenpyxlworksheet_writer.py”, line 124, in write_rows
self.write_row(xf, row, row_idx)
File “C:UsersRaytineAppDataLocalProgramsPythonPython38libsite-packagesopenpyxlworksheet_writer.py”, line 146, in write_row
write_cell(xf, self.ws, cell, cell.has_style)
File “C:UsersRaytineAppDataLocalProgramsPythonPython38libsite-packagesopenpyxlcell_writer.py”, line 45, in etree_write_cell
el = Element(“c”, attributes)
MemoryError
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File “C:UsersRaytineAppDataLocalProgramsPythonPython38libsite-packagesopenpyxlworksheet_writer.py”, line 32, in _openpyxl_shutdown
os.remove(path)
PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: ‘C:UsersRaytineAppDataLocalTempopenpyxl.iodymmm4’
不知道该如何回收内存?
最后
以上就是机灵大神为你收集整理的openpyxl处理50万行Excel数据,出现memory error问题,请教大神代码怎么修改的全部内容,希望文章能够帮你解决openpyxl处理50万行Excel数据,出现memory error问题,请教大神代码怎么修改所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复