python-docx

来源:互联网 发布:excel A列所有数据 编辑:程序博客网 时间:2024/04/27 17:50

Release v0.7.4 (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 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='IntenseQuote')document.add_paragraph(    'first item in unordered list', style='ListBullet')document.add_paragraph(    'first item in ordered list', style='ListNumber')document.add_picture('monty-truth.png', width=Inches(1.25))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 item in recordset:    row_cells = table.add_row().cells    row_cells[0].text = str(item.qty)    row_cells[1].text = str(item.id)    row_cells[2].text = item.descdocument.add_page_break()document.save('demo.docx')

User Guide

  • Installing
  • Quickstart
  • Working with Documents
  • Working with Sections
  • API basics
  • Understanding Styles
  • Understanding pictures and other shapes
  • Low-level text API

API Documentation

  • Document objects
    • Document objects
    • Sections objects
  • Table objects
    • Table objects
    • _Cell objects
    • _Row objects
    • _Column objects
    • _Rows objects
    • _Columns objects
  • Text-related objects
    • Paragraph objects
    • Run objects
  • Section objects
    • Section objects
  • Shape-related objects
    • InlineShapes objects
    • InlineShape objects
  • Shared classes
    • Length objects
  • Enumerations
    • WD_PARAGRAPH_ALIGNMENT
    • WD_ORIENTATION
    • WD_SECTION_START
    • WD_UNDERLINE

Contributor Guide

  • Analysis
1 0
原创粉丝点击