读:  

  from docx import Document
  dir_docx = 'F:\Eclipse\workspace\Spider\cnblogs_doc\mytest - 副本.docx'
  dir_docx = dir_docx.decode('utf-8')
  document = Document(dir_docx)
  for p in document.paragraphs:
    print p.text

  注意:docx的名称不能是中文,否则报错:docx.opc.exceptions.PackageNotFoundError

写:(官方文档:https://python-docx.readthedocs.io/en/latest/)

from docx import Document
from docx.shared import Inches document = Document() document.add_heading('Document Title', 0) p = document.add_paragraph('A plain paragraph having some ')
p.add_run('bold').bold = True
p.add_run(' and some ')
p.add_run('italic.').italic = True document.add_heading('Heading, level 1', level=1)
document.add_paragraph('Intense quote', style='IntenseQuote') document.add_paragraph(
'first item in unordered list', style='ListBullet'
)
document.add_paragraph(
'first item in ordered list', style='ListNumber'
) document.add_picture('monty-truth.png', width=Inches(1.25)) table = document.add_table(rows=1, cols=3)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Qty'
hdr_cells[1].text = 'Id'
hdr_cells[2].text = 'Desc'
for item in recordset:
row_cells = table.add_row().cells
row_cells[0].text = str(item.qty)
row_cells[1].text = str(item.id)
row_cells[2].text = item.desc document.add_page_break() document.save('demo.docx')

python读写word文档的更多相关文章

  1. 利用Python操作Word文档【图片】

    利用Python操作Word文档

  2. Python之word文档模板套用 - 真正的模板格式套用

    Python之word文档模板套用: 1 ''' 2 #word模板套用2:套用模板 3 ''' 4 5 #导入所需库 6 from docx import Document 7 ''' 8 #另存w ...

  3. Python之word文档替换字符串(也可以用于短模板套用)

    Python之word文档替换字符串(也可以用于短模板套用),代码如下: 1 ''' 2 #word模板套用1:创建模板,适合比较短的文档 3 ''' 4 5 #导入所需库 6 from docx i ...

  4. Python读取word文档内容

    1,利用python读取纯文字的word文档,读取段落和段落里的文字. 先读取段落,代码如下: 1 ''' 2 #利用python读取word文档,先读取段落 3 ''' 4 #导入所需库 5 fro ...

  5. Python用python-docx读写word文档

    python-docx库可用于创建和编辑Microsoft Word(.docx)文件.官方文档:https://python-docx.readthedocs.io/en/latest/index. ...

  6. python+selenium自动化软件测试(第12章):Python读写XML文档

    XML 即可扩展标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进 行定义的源语言.xml 有如下特征: 首先,它是有标签对组成:<aa></aa> ...

  7. 2018-10-04 [日常]用Python读取word文档中的表格并比较

    最近想对某些word文档(docx)的表格内容作比较, 于是找了一下相关工具. 参考Automate the Boring Stuff with Python中的word部分, 试用了python-d ...

  8. $用python-docx模块读写word文档

    工作中会遇到需要读取一个有几百页的word文档并从中整理出一些信息的需求,比如产品的API文档一般是word格式的.几百页的文档,如果手工一个个去处理,几乎是不可能的事情.这时就要找一个库写脚本去实现 ...

  9. Python读取word文档(python-docx包)

    最近想统计word文档中的一些信息,人工统计的话...三天三夜吧 python 不愧是万能语言,发现有一个包叫做 docx,非常好用,具体查看官方文档:https://python-docx.read ...

随机推荐

  1. spring sessionFactory 属性配置详解,applicationContext中各种属性详解

    1.Bean的id为sessionFactory,对应的类为AnnotationSessionFactory,即采用注解的形式实现hibernate. 2.hibernateProperties,配置 ...

  2. scikit-learn 入门练习

    1. 一个简单的SVM实例: from sklearn import svm X = [[2, 0], [1, 1], [2,3]] y = [0, 0, 1] clf = svm.SVC(kerne ...

  3. [转]玩转UltraEdit,UE常见快捷键操作

    编辑器Ultraedit快捷键说到编辑器的快捷键,VIM是无与伦比的.要反对,也得是带脚踏板的EmaCS.UE还是有差距的,很大差距.注意:VIM是开源.免费的,而UE则需要注册.UE是Windows ...

  4. HTML解析HtmlAgility学习

    HtmlAgility是一个开源的Html解析库,据说是C#版的JQuery,功能非常强大. 该篇学习它的解析功能,还可以模拟用户请求,创建html,设置代理等等,暂先不研究. ----------- ...

  5. 【Android】10.2 使用Android Support Library增强组件功能

    分类:C#.Android.VS2015: 创建日期:2016-02-18 一.简介 Android Support Library提供了一些非常漂亮的附加功能,由于这些库的引用办法都差不多,所以这一 ...

  6. angular学习笔记(四)- input元素的ng-model属性

    input元素的ng-model属性: 用于将input的值和变量的值进行双向绑定 <!DOCTYPE html> <html ng-app> <head> < ...

  7. How-to: Tune Your Apache Spark Jobs (Part 1)

    Learn techniques for tuning your Apache Spark jobs for optimal efficiency. When you write Apache Spa ...

  8. 【转】10张图带你深入理解Docker容器和镜像

    [转自]:http://dockone.io/article/783 待续

  9. js实现点击按钮实现上一张下一张相册滚动效果

    /****判断图片是否构成滚动效果*/$(function(){    if($("#bar").find('img').size()*71<=$("#bar&qu ...

  10. oracle判断查询结果是否为空

    create table test1023(id int); --创建测试表 test1023 declare cnt int; begin select count(*) into cnt from ...