艺赛旗 RPA9.0全新首发免费下载 点击下载
http://www.i-search.com.cn/index.html?from=line1
详细内容请参看艺赛旗官网支持栏目:RPA社区
点击链接进入 http://support.i-search.com.cn/
**1.**引用库
from docx import Document
**2.**新建一个空 docx
document = Document()
**3.**保存 docx
document.save(‘c:/test2.docx’)
**4.**打开指定的 docx
document = Document(‘c:/test.docx’)
**5.**在末尾增加一个段落 paragraph
paragraph = document.add_paragraph(‘Lorem ipsum dolor sit amet.’)
**6.**插入段落
使用一个段落作为“光标”,并在其上直接插入一个新段落:在段落 paragraph 前增加一个段落 prior_paragraph
prior_paragraph = paragraph.insert_paragraph_before(‘Lorem ipsum’)
**7.**添加标题
document.add_heading(‘The REAL meaning of the universe’)
增加一个级别为 2 的标题
document.add_heading(‘The role of dolphins’, level=2)
**8.**添加分页符
document.add_page_break()
**9.**添加表
table = document.add_table(rows=2, cols=2)
访问单元格:在 table 表的 0 行 1 列
cell = table.cell(0, 1)
设置单元格文本
cell.text = ‘parrot, possibly dead’