doc转docx
代码语言:javascript复制from win32com import client as wc
w = wc.gencache.EnsureDispatch('kwps.application')
doc = w.Documents.Open(r"C:\Users\Administrator\Desktop\原文件.doc")
doc.SaveAs2(r"C:\Users\Administrator\Desktop\转换格式文件.docx", 12)
docx转pdf
代码语言:javascript复制import win32com
from win32com.client import Dispatch
word = Dispatch('Word.Application')
doc = word.Documents.Open(r"C:\Users\Administrator\Desktop\原文件.docx")
doc.SaveAs(r"C:\Users\Administrator\Desktop\转PDF.pdf", 17)
doc.Close()
word.Quit()