doc转docx和docx转pdf的python代码2021.9.28

2022-09-22 08:39:35 浏览数 (2)

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()

0 人点赞