马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
求助求助,代码如下:
wb1=openpyxl.load_workbook(p1)
ws1=wb1.worksheets[0]
wb=openpyxl.load_workbook(p2)
ws=wb.worksheets[0]
r=1
for j in range(18,ws1.max_row):
for i in ws['B']:
if i.value==ws1['U' + str(j)].value:
image=ws._images[i.row-1]
image.height = 60
image.width = 60
ws1.row_dimensions[j].height = 50
ws1.row_dimensions[j].width = 50
ws1.add_image(image, 'Q' + str(j))
ws1['U' + str(j)].value=''
break
wb1.save(p1)
报错:
wb1.save(r'C:\Users\Administrator\Desktop\1.xlsx')
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\workbook\workbook.py", line 386, in save
save_workbook(self, filename)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\writer\excel.py", line 294, in save_workbook
writer.save()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\writer\excel.py", line 275, in save
self.write_data()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\writer\excel.py", line 79, in write_data
self._write_images()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\writer\excel.py", line 116, in _write_images
self._archive.writestr(img.path[1:], img._data())
^^^^^^^^^^^
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\drawing\image.py", line 48, in _data
img = _import_image(self.ref)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\openpyxl\drawing\image.py", line 16, in _import_image
img = PILImage.open(img)
^^^^^^^^^^^^^^^^^^
File "D:\pyoby\venv\Lib\site-packages\PIL\Image.py", line 3240, in open
fp.seek(0)
ValueError: I/O operation on closed file. |