Word转TXT算法实现
算法思路:
·定义文件路径和转存路径:split
·修改新的文件名:fnmatch
·设置完整的保存路径:join
·启动应用程序格式转换:Dispatch
·保存文本:SavaAs

word 转换tet思路
#coding=utf-8
import os,fnmatch
from win32com import client as wc
from win32com.client import Dispatch
def Word2Txt(filepath,savePath=''):
dirs,filename = os.path.split(filePath)
new_name=""
if fnmatch.fanmatch(filename,'*.doc'):
new_name = filename[:-4]+'.txt'
elif fnmatch.fnmatch(filename,'*.docx'):
new_name = filename[:-5]+'.txt'
else:
print("格式不正确")
return
if savePath == '':
savePath = dirs
else:
savePath = savePath
word2txtPath = os.path.join(savePath,new_name)
print('-->',word2txtPath)
wordapp = wc.Dispatch('word.Application')
mytxt = wordapp.Documents.Open(filePath)
if __name__=='__main__':
filePath = os.path.abspath(r'../../*.doc')
word2Txt(filePath)
shift+alt+数字 分页
miooooioio
电脑上必须安装word,不然会出现 无法找到程序的错误
******
Pywin32实现格式转换
插件:win32com
下载:pip install pywin32
引入:from win32com import client as wc


Word转txt算法实现
Pywin32实现格式转换