将doc转存为docx
from win32com.client import Dispatch
import sys
import os
def docToDocx(docPath, new_doc):
'''将doc转存为docx'''
word = Dispatch('kwps.Application')
pathPrefix = sys.path[0]+'\\'
doc = word.Documents.Open(pathPrefix+docPath)
docxPath = "wewewewe.docx"
doc.SaveAs(os.path.join(new_doc, docxPath), FileFormat=12)
doc.Close()
word.Quit()
if __name__ == '__main__':
old_doc = "Wewqewqe.doc"
new_doc = r"C:\Users\HEJEN\Desktop\pytest\Wewqewqe"
if not os.path.exists(new_doc):
os.mkdir(new_doc)
print("=====================目录创建成功======================")
docToDocx(old_doc, new_doc)
print("=====================docx格式转换成功===================")