⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makerealworddoc.py

📁 Dive into Python 中文版
💻 PY
字号:
"""Convert HTML page to Word 97 documentThis script is used during the build process of "Dive Into Python"(http://diveintopython.org/) to create the downloadable Word 97 versionof the book (http://diveintopython.org/diveintopython.doc)Looks for 2 arguments on the command line.  The first argument is the input (HTML)file; the second argument is the output (.doc) file.Only runs on Windows.  Requires Microsoft Word 2000.Safe to run on the same file(s) more than once.  The output file will besilently overwritten if it already exists."""__author__ = "Mark Pilgrim (mark@diveintopython.org)"__version__ = "$Revision: 1.2 $"__date__ = "$Date: 2004/05/05 21:57:19 $"__copyright__ = "Copyright (c) 2001 Mark Pilgrim"__license__ = "Python"import sys, osfrom win32com.client import gencache, constantsdef 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 wordif __name__ == "__main__":	infile = os.path.normpath(os.path.join(os.getcwd(), sys.argv[1]))	outfile = os.path.normpath(os.path.join(os.getcwd(), sys.argv[2]))	makeRealWordDoc(infile, outfile)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -