python docx API 之 Document
Document API
参考:https://python-docx.readthedocs.io/en/latest/api/document.html
#1.构造函数,返回Document对象
document = Document(docx=None)
#2.添加标题
add_heading(text=u'', level=1)
#3.增加分页符
add_page_break()
#4.增加段落,text中可以包括换行符,tab符等特殊符号
add_paragraph(text=u'', style=None)
#5.添加图片
add_picture(image_path_or_stream, width=None, height=None)
#6.添加分节
add_section(start_type=2)
#7.添加表格
add_table(rows, cols, style=None)
#8.访问核心属性
#核心属性包括:
#author, category, comments, content_status,
#created, identifier, keywords, language, last_modified_by,
#last_printed, modified, revision, subject, title,version
core_properties
#9.访问行内属性
inline_shapes
#10.返回段落列表
paragraphs
#11.保存文档
save(path_or_stream)
#12.part
#The DocumentPart object of this document.
#13.访问分节
sections
#14.访问document-level settings
settings
#15.访问样式设置
styles
#16.访问表格,返回列表
tables
浙公网安备 33010602011771号