import os
import win32com
from win32com.client import Dispatch
def doctodocx(filepath,newpath):
filelist =os.listdir(filepath)
filelists=[]
for f in filelist:
if f.endswith('doc'):
filelists.append(f)
# w = win32com.client.Dispatch('Word.Application')
# w.Visible=0
for f in filelists:
filename = os.path.join(filepath,f)
w = win32com.client.Dispatch('Word.Application')
w.Visible=0
doc = w.Documents.Open(filename)
target = newpath+'\\'+f[:-3]+'docx'
doc.SaveAs(target,16)
doctodocx(r'C:\Users\Administrator\Desktop\4',r'C:\Users\Administrator\Desktop\docx')
网友评论