1.Python操作Word文档所需的第三方库
from docx import Document
from docx.shared import Pt, Cm, Inches, RGBColor
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.oxml.ns import qn
from docx import Document
from docx.enum.style import WD_STYLE_TYPE, WD_BUILTIN_STYLE
from docx.enum.table import WD_CELL_VERTICAL_ALIGNMENT
2.编辑Word文档
doc = Document()
doc.add_heading('标题内容',level=1)
doc.add_paragraph('段落内容')
doc.add_page_break()
table = doc.add_table(3,4)
table.cell(1,1).text = '表格内容'
doc.add_picture('fifles/xizang.JPG',width=Cm(15.2))
doc.save('fifles/1.docx')
3.设置基本样式
from docx.shared import Pt, Cm, Inches, RGBColor
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.oxml.ns import qn
doc = Document()