亲测真是有效!在国内平台未搜到有效代码,在国外网站https://www.programmerall.com/article/1705387316/找到的可以实现!!!呜呜呜,终于!太感谢了!国内网站搜不到就试试英文关键字必应搜索国际版吧!!!
#首先得安装pywin32库,此处省略
import os
from win32com.client import Dispatch,DispatchEx,constants
def doc_to_docx(f_path):
w=Dispatch('Word.Application')
doc=w.Documents.Open(f_path)
new_path=os.path.splitext(f_path)[0]+'.docx'
doc.SaveAs(new_path,12,False,'',True,'',False,False,False,False)
doc.Close()
w.Quit()
return new_path
path=r'E:\Desktop\doc文件夹'
docfiles=[]
filename=os.listdir(path)
for file in filename:
docfile=os.path.join(path,file)
docfiles.append(docfile)
for file in docfiles:
try:
doc_to_docx(file)
print(file+'done!')
except:
print(file+'unununundone!')
continue