python在docx文件上的应用

python在docx文件上的应用

python-docx模块

python-docx模块的基本运用

python-docx模块

python-docx模块用于实现读取docx文件的功能

python-docx模块下载

pip3 install python -i 路径地址

国内路径

    (1)阿里云 http://mirrors.aliyun.com/pypi/simple/2)豆瓣 http://pypi.douban.com/simple/3)清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/4)中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/5)华中科技大学http://pypi.hustunique.com/

 

python-docx模块的基本运用

调用模块

import docx

获取文本数据

# 建立变量,获取文本地址
file=docx.Document("new1.docx")
# 输出文章段落
print("段落数:"+str(len(file.paragraphs)))

 

变量本身为一个迭代器

print(file)
print()

 

 只有逐行获取数据

for i in file.paragraphs:
    print(i.text)

返回目录

posted @ 2021-11-24 22:03  微纯册  阅读(106)  评论(0)    收藏  举报