def makeRealWordDoc(infile, outfile):
word = gencache.EnsureDispatch("Word.Application")
try:
worddoc = word.Documents.Open(FileName=infile)
try:
worddoc.TablesOfContents.Add(Range=word.ActiveWindow.Selection.Range, \
RightAlignPageNumbers=1, \
UseHeadingStyles=1, \
UpperHeadingLevel=1, \
LowerHeadingLevel=2, \
IncludePageNumbers=1, \
AddedStyles='', \
UseHyperlinks=1, \
HidePageNumbersInWeb=1)
worddoc.TablesOfContents(1).TabLeader = constants.wdTabLeaderDots
worddoc.TablesOfContents.Format = constants.wdIndexIndent
word.ActiveWindow.ActivePane.View.SeekView = constants.wdSeekCurrentPageHeader
word.Selection.TypeText(Text="Dive Into Python\t\thttp://diveintopython.org/")
word.ActiveWindow.ActivePane.View.SeekView = constants.wdSeekCurrentPageFooter
word.NormalTemplate.AutoTextEntries("- PAGE -").Insert(Where=word.ActiveWindow.Selection.Range)
word.ActiveWindow.View.Type = constants.wdPrintView
worddoc.TablesOfContents(1).Update()
worddoc.SaveAs(FileName=outfile, \
FileFormat=constants.wdFormatDocument)
finally:
worddoc.Close(0)
del worddoc
finally:
word.Quit()
del word
评论列表
文章目录