problem controlling MS Word from Python
Mark Hammond
MarkH at ActiveState.com
Sat Oct 6 22:56:44 EDT 2001
Andrew Brown wrote:
> "Travers Naran" <tnaran at direct.ca> wrote in
> <9plt6r0e3b at enews1.newsguy.com>:
>
>
>>Could you post some sample of your code? I have Office 97 on my machine
>>(with HTML saving extensions). I'd be interested to see if it happens
>>in the older Office as well.
>>
>>
>>
>>
> I did post some earlier, and I'm reulctant to clutter the list, but here is
> the relevant bit again: it is office 97 that I have been using. Some lines
> have wrapped, but it should be ovious which, and where. I could post the
> whole lot if you really want, but that seems rude -- and pointless unless
> you have PyQT.
Is is possible to reduce it down to a small, stand-alone script that we
can run to see the crash? If you can get it down to 10 lines or so that
I can execute and see it die, then there is much more chance of seeing a
solution...
Mark.
>
>
>
> def domydir(self):
> "Processes all the .doc files in a directory using do_that_thing
> ()"
> QApplication.setOverrideCursor(Qt.waitCursor)
> try:
> self.o=win32com.client.Dispatch('Word.Application')
> self.o.Visible=1
> except:
> warning='OLE fuckup! ' + str(sys.exc_type) + str
> (sys.exc_value)
> self.btn_dirpick.setText(warning)
> mypath,myfile=os.path.split(str(self.wombat_txt))
> os.chdir(mypath)
> self.o.ChangeFileOpenDirectory(mypath)
> # show what we're doing on the button
> for wombats in os.listdir(os.getcwd()):
> if string.find(wombats, 'doc')>1:
> htmlfile=self.htmlext(wombats)
> self.do_that_thing(wombats,htmlfile)
> print 'have just processed', htmlfile
> QApplication.restoreOverrideCursor()
>
>
> And
>
> def do_that_thing(self,docfile,htmlfile):
> '''gets an instance of word, to save the docfile as html.'''
> try:
> self.o.Documents.Add(docfile)
> self.o.ActiveDocument.SaveAs(htmlfile,17)
> self.o.ActiveDocument.Close()
> except:
> warn='DO that Thing! ' + str(sys.exc_type) + str
> (sys.exc_value)
> self.btn_dirpick.setText(warn)
>
>
>
>
>
More information about the Python-list
mailing list