Error description
The immediate cause of the error is trying to open a table file that was not previously closed. This error could be caused by:
In the process before
- the workbook that was opened did not have a normal close, resulting in additional temporary files, and errors occurred when trying to open these temporary files; The workbook before
- did not overwrite the existing files when saving.
can also be other errors, but it doesn’t matter, look at the solution, you can from the root to avoid this kind of error about load/save .
solution
open and exit excel files in a safe way, you can avoid the above type of load/save error. When opening a file, open excel in the following ways: if the original file already exists, just load it directly; If it doesn’t exist, create a new workbook and prepare the last save.
import os
from openpyxl import Workbook
from openpyxl import load_workbook
if os.path.exists(new_filename):
new_wb = load_workbook(new_filename)
else:
new_wb = Workbook()
is safely saved as excel
- first, remember to exit as soon as you run out of files. Second, when exiting a file, for all workbooks, if you need to save, if you don’t need to save (read-only), be sure to close
wb.save(filename) # For workbooks that need to save written content
wb.close() # Read-only workbook for the program
Read More:
- [Solved] Cannot open .xlsx file, xlrd.biffh.XLRDError: Excel xlsx file; not supported
- Pyexcel Error: xlrd.biffh.XLRDError: Excel xlsx file; not supported
- [Solved] Python project runs the open() function error: FileNotFoundError: [Errno 2] No such file or directory
- Python Pandas Error: No module named ‘openpyxl‘
- PIP Install Mysqlclient error C1083: Cannot open include file: ‘mysql.h‘: No such file or directory
- Tensorflow import Error: ImportError: libcuda.so.1: cannot open shared object file: No such file or dire
- [Solved] Python Read bam File Error: &&OSError: no BGZF EOF marker; file may be truncated
- [Solved] Import cv2 Error: ImportError: libGL.so.1: cannot open shared object file: No such file or directory
- ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
- Python FileNotFoundError: [Errno 2] No such file or directory: ‘objects/epsilon.pkl
- Python environment error, bad interpreter: there is no file or directory
- Python Grpc Error: A file with this name is already in the pool
- Chromdriver Install error: File “C:\python37\lib\site-packages\selenium\webdriver\common\service.py”, line 76, in start stdin=PIPE) File…
- [zipfile] Python packages files as zip packages & decompresses them
- Python: How to Encode the File (including HTML, TXT, Doc, etc.)
- Python + Requests +Excel+Jenkins interface automation
- How to Fix Python reading large local file memory error
- Python writes DICOM file (attributeerror: ‘filemetadataset’ object has no attribute ‘transfersyntax uid’ solution)
- python: File Processing and Input and Output
- Python reads excel and stores it in the list according to the header hash copy.deepcopy