Windows Automation In Python
时间:2006-12-16 来源:qingfa
import fnmatch, os, sys, win32com.client
wordapp = win32com.client.gencache.EnsureDispatch("Word.Application")
try:
for path,dirs,files in os.walk(sys.argv[1]):
for filename in files:
if not fnmatch.fnmatch(filename,'*.doc'):continue
doc= os.path.abspath(os.path.join(path,filename))
print "processing %s" %doc
wordapp.Documents.Open(doc)
docastxt = doc[:-3]+'txt'
wordapp.ActiveDocument.SaveAs(docastxt,FileFormat=win32com.client.constants.wdFormatText)
wordapp.ActiveDocument.Close()
finally:
wordapp.Quit()
wordapp = win32com.client.gencache.EnsureDispatch("Word.Application")
try:
for path,dirs,files in os.walk(sys.argv[1]):
for filename in files:
if not fnmatch.fnmatch(filename,'*.doc'):continue
doc= os.path.abspath(os.path.join(path,filename))
print "processing %s" %doc
wordapp.Documents.Open(doc)
docastxt = doc[:-3]+'txt'
wordapp.ActiveDocument.SaveAs(docastxt,FileFormat=win32com.client.constants.wdFormatText)
wordapp.ActiveDocument.Close()
finally:
wordapp.Quit()
相关阅读 更多 +