ValueError: I/O Operation on closed file on<filename>)

Issue #1164 closed
Divij Sehgal
created an issue

Appending result to intermediate file: /home/divij/Desktop/Divij/Personal/Email_finder_and_sender/Email_finder_and_sender/12_AU_BETA.xlsx Image File to include: /home/divij/Desktop/Divij/Personal/Email_finder_and_sender/Email_finder_and_sender/Prints/Dentist Sydney-data.png

Traceback (most recent call last):
  File "", line 700, in <module>
    apppendIntermediateResultsToFile(filesPath["excel"], local_output, googleSearch.printsFolder)
  File "", line 536, in apppendIntermediateResultsToFile
  File "/home/divij/Desktop/Divij/Personal/venv/lib/python3.6/site-packages/openpyxl/workbook/", line 391, in save
    save_workbook(self, filename)
  File "/home/divij/Desktop/Divij/Personal/venv/lib/python3.6/site-packages/openpyxl/writer/", line 284, in save_workbook
  File "/home/divij/Desktop/Divij/Personal/venv/lib/python3.6/site-packages/openpyxl/writer/", line 266, in save
  File "/home/divij/Desktop/Divij/Personal/venv/lib/python3.6/site-packages/openpyxl/writer/", line 85, in write_data
  File "/home/divij/Desktop/Divij/Personal/venv/lib/python3.6/site-packages/openpyxl/writer/", line 122, in _write_images
    self._archive.writestr(img.path[1:], img._data())
  File "/home/divij/Desktop/Divij/Personal/venv/lib/python3.6/site-packages/openpyxl/drawing/", line 64, in _data
    img = _import_image(self.ref)
  File "/home/divij/Desktop/Divij/Personal/venv/lib/python3.6/site-packages/openpyxl/drawing/", line 33, in _import_image
    img =
  File "/home/divij/Desktop/Divij/Personal/venv/lib/python3.6/site-packages/PIL/", line 2638, in open
ValueError: I/O operation on closed file.

I am getting the above error while trying to save workbook to file. In the save command, I have used the exact statements required to save a workbook to an excel file, but I get this everytime.

Google suggests that a file must be open. But I cannot pass the file object to<filename>) function as it can only take a filename so that has turned out futile.

Any suggestions what might be going wrong here?

Comments (3)

  1. CharlieC

    I'm not really sure what you're trying to do but the problem is related to the image file you've added to the worksheet. This is not really to do with openpyxl but with your file system.

    Please do not use the bug tracker to ask questions, that's what the mailing list is for.

  2. Divij Sehgal reporter

    Apologies. This surely seemed like a bug to me, since I could not work with a worksheet without the image where I should've been able to. Thanks for nudging me in the right direction.

  3. Log in to comment