Java教程

批量将word数据写入txt文件

本文主要是介绍批量将word数据写入txt文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
# In[1]
import os
from docx import Document


dir_lists = os.listdir()

for dir in dir_lists:
    if os.path.isdir(dir):
        # print(dir)
        words_lst = os.listdir(dir)
        for word in words_lst:
            url_path = os.getcwd()
            url_path = url_path + '\\' + dir + '\\'
            url_path = url_path + word
            print(url_path[:-5])
            if word.find('txt') != -1:
                continue
            f = open(url_path[:-5] + '.txt', 'w', encoding='utf-8')
            file = Document(url_path)
            print('段落数:'+str(len(file.paragraphs)))
            for para in file.paragraphs:
                f.write(para.text)
            f.close()

这篇关于批量将word数据写入txt文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!