P002-将word文档内容复制到text文件中

convert_to_txt.py

import docx

doc = docx.Document('/work/sourcedir/output0951.docx')

text = ''
for paragraph in doc.paragraphs:
    text += paragraph.text + '\n'

with open('/work/sourcedir/output0951.txt', 'w') as file:
    file.write(text)

如果没有doc库则安装 pip install python-docx
日期:2024-02-28

posted @ 2024-02-28 11:39  ysloong  阅读(5)  评论(0编辑  收藏  举报