python python-docx办公自动化 *** 作word

python python-docx办公自动化 *** 作word,第1张

概述fromdocximportDocumentfromdocx.sharedimportInchesdocument=Document()document.add_heading('DocumentTitle',0)p=document.add_paragraph('Aplainparagraphhavingsome')p.add_run('bold').bold=Truep.add_run(
from docx import documentfrom docx.shared import Inchesdocument = document()document.add_heading('document Title', 0)p = document.add_paragraph('A plain paragraph having some ')p.add_run('bold').bold = Truep.add_run(' and some ')p.add_run('italic.').italic = Truedocument.add_heading('heading, level 1', level=1)document.add_paragraph('Intense quote', style='Intense Quote')document.add_paragraph(    'first item in unordered List', style='List Bullet')document.add_paragraph(    'first item in ordered List', style='List Number')# document.add_picture('monty-truth.png', wIDth=Inches(1.25))records = (    (3, '101', 'Spam'),    (7, '422', 'Eggs'),    (4, '631', 'Spam, spam, eggs, and spam'))table = document.add_table(rows=1, cols=3)hdr_cells = table.rows[0].cellshdr_cells[0].text = 'Qty'hdr_cells[1].text = 'ID'hdr_cells[2].text = 'Desc'for qty, ID, desc in records:    row_cells = table.add_row().cells    row_cells[0].text = str(qty)    row_cells[1].text = ID    row_cells[2].text = descdocument.add_page_break()#添加页眉section=document.sections[0]header=section.headerparagraph = header.paragraphs[0]paragraph.text = "left Text\tCenter Text\tRight Text"paragraph.style = document.styles["header"]document.save('demo.docx')

 

总结

以上是内存溢出为你收集整理的python python-docx办公自动化 *** 作word全部内容,希望文章能够帮你解决python python-docx办公自动化 *** 作word所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1186349.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存