wordapp = win32com.client.gencache.EnsureDispatch("Word.Application")
try:
wordapp.Documents.Open('11.doc')
wordapp.ActiveDocument.SaveAs('11.html', FileFormat=win32com.client.constants.wdFormatFilteredHTML)
wordapp.ActiveDocument.Close()
finally:
wordapp.Quit()
office2007中所支持的格式:
wdFormatDocument = 0
wdFormatDocument97 = 0
wdFormatDocumentDefault = 16
wdFormatDOSText = 4
wdFormatDOSTextLineBreaks = 5
wdFormatEncodedText = 7
wdFormatFilteredHTML = 10
wdFormatFlatXML = 19
wdFormatFlatXMLMacroEnabled = 20
wdFormatFlatXMLTemplate = 21
wdFormatFlatXMLTemplateMacroEnabled = 22
wdFormatHTML = 8
wdFormatPDF = 17
wdFormatRTF = 6
wdFormatTemplate = 1
wdFormatTemplate97 = 1
wdFormatText = 2
wdFormatTextLineBreaks = 3
wdFormatUnicodeText = 7
wdFormatWebArchive = 9
wdFormatXML = 11
wdFormatXMLDocument = 12
wdFormatXMLDocumentMacroEnabled = 13
wdFormatXMLTemplate = 14
wdFormatXMLTemplateMacroEnabled = 15
wdFormatXPS = 18
单元格另存为,因为没找到部分另存为的vba代码,所以调用copy&paste曲线解决
def saveCell(self, savePath, cell):
tmpDoc = cell.Application.Documents.Add()
#内容为空则End=Start,如果这时Copy则将会Copy到表格
if not cell.Range.Text[0:len(cell.Range.Text)-2] == '':#不成立时则保存空的doc文件
start = cell.Range.Start
end = cell.Range.End
if end>start:
cell.Range.Document.Range(cell.Range.Start, cell.Range.End-1).Copy()
else:
cell.Range.Document.Range(cell.Range.Start, cell.Range.End).Copy()
tmpDoc.Range(0, 0).Paste()
tmpDoc.SaveAs(sys.path[0]+os.sep+'HTML'+os.sep+savePath, FileFormat=win32.constants.wdFormatFilteredHTML)
tmpDoc.Close(SaveChanges=win32.constants.wdDoNotSaveChanges)
分享到:
相关推荐
"取word打开、另存为对话框窗口句柄"这个主题涉及到Windows操作系统中的句柄概念,以及如何通过编程来操控Word应用程序的特定对话框。下面我们将深入探讨这个主题。 首先,句柄是Windows API(应用程序接口)中的一...
当我们谈论"取word打开、另存为对话框窗口句柄"时,这涉及到的是自动化脚本编写或者应用程序接口(API)调用,通常是为了自动化Word文档的操作,如自动打开、保存或另存文件。 在Microsoft Word中,"打开"和"另存为...
使用Python控制Microsoft Word是一项实用的技术,它允许程序员自动化文档处理任务,例如创建、编辑和打印文档。这在处理大量文档时特别有用。Python通过`win32com`库实现了与Windows应用程序,如MS-Word的交互。以下...
在这种情况下,我们可以利用`win32com.client`模块,这是一个Python接口,用于访问和控制COM(Component Object Model)对象,使得我们可以像直接操作Word软件一样来处理Word文档。本文将详细介绍如何使用Python通过...
# 另存为新的文件 newdoc.SaveAs(r'D:\b.doc') # 关闭新文档 newdoc.Close() # 关闭Word应用程序 w.Documents.Close() w.Quit() ``` #### 三、关键步骤详解 1. **创建Word应用程序对象**: - 使用`win32...
# 将Word文档另存为文本文件 doc.SaveAs('c:/test.text', 4) # 关闭文档 doc.Close() # 关闭Word应用 word.Quit() ``` 这段代码展示了如何使用`win32com`库读取一个Word文档并将其转换为文本文件。这里有几个关键...