How to check if an online Excel file is in use by another user?

453 views Asked by At

I have a Microsoft Excel file on OneDrive. When my Python script saves anything to the file and the file is already open, OneDrive raises an error, telling me there is a sync issue.

If the file is closed(not in use by another user), everything works great.

Is there was a way to check if the file is currently in use by another person?

I forgot to mention that the file on onedrive is a shortcut to a sharepoint file.

2

There are 2 answers

2
Szymon Kocot On

In case you have sheet.xlsx and someone has opened it, you should see ~$sheet.xlsx file in the same directory.

-rw-r--r--@  1 szymon  szymon   9431 Oct  2 11:41 sheet.xlsx
-rw-r--r--@  1 szymon  szymon    165 Oct  2 11:45 ~$sheet.xlsx
1
Trolling Killer On

Will it help you?

try:
    with open("file_name", "r") as file:
        print("File has opened for reading.")
except IOError:
    print("Error, The File is open.")