I have searched far and wide, but can't find the right solution. All I want to do is get a sum and count of a column and insert that sum in to another workbook. That works fine when no one is in the source workbook. I can easily open the file by going to the file and clicking read only. I can also still right click > copy, then paste it as well, but can't seem to do either of these with Python while it is in use.
If this is a duplicate, I apologize in advance.
This is simply using the basic open or copy functions.
shutil.copy(src, dst) #For the copy procedure
openpyxl.load_workbook(file) #For just the open and read
Both of these functions basically produce the similar errors when the file is in use by another user.
Traceback (most recent call last):
File "myfile.py", line 14, in <module>
sbwb = openpyxl.load_workbook(sbfile)
File "C:\Python27\lib\site-packages\openpyxl\reader\excel.py", line 164, in
load_workbook
archive = _validate_archive(filename)
File "C:\Python27\lib\site-packages\openpyxl\reader\excel.py", line 118, in
_validate_archive
archive = ZipFile(filename, 'r', ZIP_DEFLATED)
File "C:\Python27\lib\zipfile.py", line 778, in __init__
self.fp = io.open(file, filemode)
IOError: [Errno 13] Permission denied:
'file location'
UPDATE I found the issue and it wasn't related to Python at all. What was happening was that I was searching for the latest file in the folder. When the code searches in the folder, it finds the locked file before the original. I just excluded files that begin with ~$ and it found the correct one and loaded it successfully and that was using openpyxl. Thanks for everyones responses.