赞
踩
from docx import Document import os from win32com import client file_name="D:/BaiduNetdiskDownload/文案大全汇总" file_list=os.listdir(file_name) data_list=[] for one_file in file_list: dir_file_name=file_name+"/"+one_file data_list.append(one_file+"\r") if "docx" in dir_file_name: try: data=Document(dir_file_name) data_list+=[i.text.strip()+"\r" for i in data.paragraphs] except: print() else: word = client.Dispatch("Word.Application") # print("已处理文件:"+files[0]) # 打开文件 try: doc = word.Documents.Open(dir_file_name) doc.SaveAs("{}x".format(dir_file_name), 12) # 12表示docx格式 doc.Close() os.remove(dir_file_name) except: print("没有正常") with open("25.txt","w",encoding="utf-8") as f: f.writelines(data_list)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。