open excel file while it is being used.

B

barry.zhao

Hi,

I have a python program that constantly updates an excel spreadsheet.
I would like to be able to view its updates while using excel to edit
other excel files. Below are the test codes I have:

--------------------------------------------------------------------------------------
from time import sleep
import win32com.client as w32c

def test():
w32c.pythoncom.CoInitialize()
print w32c.pythoncom._GetInterfaceCount()
app1 = w32c.Dispatch("Excel.Application")
#app1.Visible=False
#app1.Interactive = False
wb=app1.Workbooks.Open("c:\\temp\\Book1.xls")

sleep(3)
sh=wb.Sheets("Sheet1")
sh.Cells(2,1).Value = "Hello, world!"
sh = None

wb.Save()
wb = None
app1 = None
w32c.pythoncom.CoUninitialize()
print w32c.pythoncom._GetInterfaceCount()
-------------------------------------------------------------------------------------

If the user just looks at the file then it's fine, but if the user
double clicks one cell, which will have a cursor flashing in the cell,
then it will lead to a crash of the program with error: "Call was
rejected by callee." I can make the program keep trying to access the
file, but if the user doesn't make the flashing cursor disappear, the
program will wait forever!

I know excel has the fuction such that when a user is accessing a file
and other users open that file, it will prompt for options of opening
it as read-only or sending notification. I have been trying to
implement that in the program, but don't know how.

So, any suggestion will be greatly appreciated!

- Barry
 
D

Devraj

Hi Barry,

Obviously what you are trying to do is detect file locks. I am not
exactly sure how to do this in Python but from previous system
administration jobs here are some scenarios that you might want to
watch out for.

- I know for one that if you are accessing the file on a Samba share,
file locking with OpenOffice or Excel have strange things happen to
them

- I am also aware that the same thing works different if the files are
shared from a Windows server and accessed on a Linux machine, and
depends on the version of Samba/Linux kernel you are running
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top