makerealworddoc.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:dive-into-python 作者: Apress 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号