[转] python-docx

https://python-docx.readthedocs.io/en/latest/

 

https://gitcode.net/mirrors/python-openxml/python-docx/-/tree/master/docx

 

python-docx

Release v0.8.11 (Installation)

python-docx is a Python library for creating and updating Microsoft Word (.docx) files.

What it can do

Here’s an example of what python-docx can do:

img
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='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].cells
hdr_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 = desc

document.add_page_break()

document.save('demo.docx')

User Guide

 

posted on   freeliver54  阅读(175)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
历史上的今天:
2019-01-27 [转]Database Transactions in Laravel
2018-01-27 [转]React 教程
2018-01-27 [转]VS2012正则查找
2015-01-27 [转]在asp.net mvc中使用PartialView返回部分HTML段
2015-01-27 [转]Asp.net MVC中Html.Partial, RenderPartial, Action,RenderAction 区别和用法
2014-01-27 [转]position:relative leaves an empty space

导航

点击右上角即可分享
微信分享提示