GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - aboater/python-docx: Create and modify Word documents with Python

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

977 Commits
977 Commits

Folders and files

NameName
Last commit message
Last commit date
docs
docs
 
 
docx
docx
 
 
features
features
 
 
ref
ref
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
HISTORY.rst
HISTORY.rst
 
 
LICENSE
LICENSE
 
 
MANIFEST.in
MANIFEST.in
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
requirements.txt
requirements.txt
 
 
setup.py
setup.py
 
 
tox.ini
tox.ini
 
 

Repository files navigation

这个 Fork 主要添加了 commentsPart ,也就是说,docx 可以使用批注啦!

下面是一个简单的例子:

You can add comments to a document with this fork of the python-docx.

A simple demonstration is as follow:

from docx import Document
from docx.shared import Inches
import time

document = Document()

heading = document.add_heading('Document Title', 0)
comment = document.add_comment_for(heading, "这是标题")
comment.author = "aboater"
comment.date = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())

p = document.add_paragraph('A plain paragraph having some ')
p.add_run('bold').bold = True
run = p.add_run(' and some ')
p.add_run('italic.').italic = True

comment = document.add_comment_for(p, "这是段落")
comment.author = "aboater"
comment.date = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())
print(comment.date)

comment = document.add_comment_for(run, "这是文字")
comment.author = "aboater"
comment.date = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())

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'
)

records = (
    (3, '101', 'Spam'),
    (7, '422', 'Eggs'),
    (4, '631', 'Spam, spam, eggs, and spam')
)

table = document.add_table(rows=1, cols=3)

comment = document.add_comment_for(table, "这是表格")
comment.author = "aboater"
comment.date = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())

print(document.remove_comment_of(table))

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
    comment = document.add_comment_for(row_cells[2], "这是表格的一个空格")
    comment.author = "aboater"
    comment.date = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())
    print(comment.date)
    print(document.remove_comment_of(row_cells[2]))


document.add_page_break()

document.save('demo.docx')

更多教程请点击原作者的教程。

More information is available in the python-docx documentation.

About

Create and modify Word documents with Python

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.