python 3 | doc转docx

python 3 | doc转docx

由于python 3 中 python-docx包只能对docx操作。
path_original 、path_final 为绝对路径,精确到.doc/.docx

def doc_to_docx(path_original, path_final):
    if os.path.splitext(path_original)[1] == ".doc":
        word = client.Dispatch('Word.Application')
        print(path_original)
        doc = word.Documents.Open(path_original)  # 目标路径下的文件
        print(path_final)
        doc.SaveAs(path_final, 16)  # 转化后路径下的文件
        doc.Close()
        word.Quit()
    elif os.path.splitext(path_original)[1] == ".docx":
        shutil.copy(path_original, path_final)

姊妹篇

python 3| docx的读写 | excel的读 | word行中添加新的key-value - 我是一块小石头 - CSDN博客
https://blog.csdn.net/stone_fall/article/details/96428915
python 3 | doc转docx - 我是一块小石头 - CSDN博客
https://blog.csdn.net/stone_fall/article/details/96428876
Python 3 | txt转Excel | 用拼音+数字对各个数据元编码 | 读取多个文件夹内容 | import xlwt + xpinyin + os - 我是一块小石头 - CSDN博客
https://blog.csdn.net/stone_fall/article/details/96428734

你可能感兴趣的:(python)