I have a python applicaiton that need to luanch a word document . is there any option to luanch a word document with read mode only from python ?
+2
A:
You will find some very useful samples on the following page:
Opening a Word document read-only can be achieved like this, False
as the third parameter to Application.Documents.Open
tells Word to open the document read-only.
import win32com.client, pythoncom, time
def word(wordfile):
pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)
myWord = win32com.client.DispatchEx('Word.Application')
myDoc = myWord.Documents.Open(wordfile, False, False, False)
...
myDoc.Close()
myWord.Quit()
del myDoc
del myWord
pythoncom.CoUninitialize()
0xA3
2010-10-21 20:41:13
It really help but do you know why this is works only from the second calling to the function word ?
AKM
2010-10-21 21:40:14
@AKM: What happens the first time?
0xA3
2010-10-21 22:07:46
It do nothing but I see a Winword application running on the task Manager
AKM
2010-10-21 22:12:39
@AKM: Try to find out, whether the line that opens the document is actually reached the first time and try stepping through the code.
0xA3
2010-10-21 22:20:00
+1
A:
You could always fire up the msword from command line via the command (Check the path)
C:\Program Files\Microsoft Office\Office\Winword.exe /f <filename>
I am assuming you want to launch msword and not read word docs programmatically. To be able to do that from python, you need to use the facility to run external commands.
see : http://docs.python.org/library/os.html#os.system
import os
os.system(command)
or:
import os
import subprocess
subprocess.call(command)
See the various command line options at:
pyfunc
2010-10-21 20:42:22
this really help but winword.exe is founded under officexx that means my python application will not work under some officexx that different from the oficeYY which found on my pc
AKM
2010-10-21 21:41:37
@AKM: winword.exe is usually on the path so just try using winword.exe without the path.
pyfunc
2010-10-21 21:49:11