Friday, December 27, 2002
Based on some code from this article, here's how to extract the "Title" property from a Word document in python.
import win32com.client
app = win32com.client.Dispatch('Word.Application')
doc = app.Documents.Add(self.filename)
self.title = doc.BuiltinDocumentProperties("Title")
doc.Close(0)
app.Quit()
3:25:43 PM
#
Hmm. There has got to be a faster way of getting that info. I'm pretty sure that Explorer isn't launching Word every time it wants to display the properties for a document.
3:47:27 PM
#
There is: FPropSet. This is about two magnitudes of order faster than the previous solution.
fps = win32com.client.Dispatch('FilePropertySet.FilePropertySet')
fps.Pathname = file
print fps.BuiltInFileProperties().Item("Title")
6:30:51 PM
#
After spending an hour trying to figure out what misunderstanding of COM was causing my problem, I realized that the file I was trying to test against DID NOT EXIST (typo). I was calling everything correctly, but the information I was sending was wrong... note that setting fps.Pathname to a non-existent file will cause an exception.
6:33:41 PM
#
|
© Copyright 2003 Brian St. Pierre.
Last update: 1/3/2003; 8:34:44 AM.
|
|