Skip to main content

Add Word comments to matching text in .docx files.

Project description

word-comment

word-comment adds a Microsoft Word comment to matching text in a .docx file.

It targets a specific paragraph by w14:paraId, finds the first matching occurrence of target_text inside that paragraph, and inserts a standard Word comment range plus comment metadata.

Installation

python -m pip install word-comment

Python API

from word_comment import add_comment

result = add_comment(
    input_path="input.docx",
    output_path="output.docx",
    para_id="7BD69366",
    target_text="keyword",
    comment_text="comment body",
    author="Auto_Bot",
)

print(result.success)
print(result.inserted_count)
print(result.reason)

CLI

word-comment input.docx output.docx 7BD69366 "keyword" "comment body" --author Auto_Bot

Behavior

  • Searches for the paragraph whose w14:paraId matches para_id
  • Finds the first occurrence of target_text in that paragraph
  • Inserts a Word comment range and a commentReference
  • Creates word/comments.xml when it does not already exist
  • Adds the required relationship and content-type entries when needed
  • Copies the input file unchanged when the paragraph or target text is not found

Return Value

add_comment(...) returns AddCommentResult with:

  • success: bool
  • inserted_count: int
  • para_id: str
  • output_path: Path
  • reason: str | None

Possible reason values:

  • paragraph_not_found
  • target_text_not_found

Limitations

  • The target paragraph must already have a w14:paraId
  • target_text must exist entirely within a single w:t node
  • Only the first match in the selected paragraph is annotated
  • The implementation modifies word/document.xml and word/comments.xml

Development Release Check

Build artifacts locally:

python -m build
python -m twine check dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

word_comment-0.1.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

word_comment-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file word_comment-0.1.0.tar.gz.

File metadata

  • Download URL: word_comment-0.1.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for word_comment-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7c705905ad60fd4bb77a1ba8204707720448aca5a9b968d97065cb53cc3e75ca
MD5 9af683944f58e5229637eaaa25327b01
BLAKE2b-256 ef23b865da2e7bb09e3f2f2a7356dc80ec4297afe150e2fe7df78501e5605962

See more details on using hashes here.

File details

Details for the file word_comment-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: word_comment-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for word_comment-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff2f107e876bd75c1f378b03f549335d4543a4b15a496b07e9d84ae163ec856f
MD5 b245643028322b680999528a01d0c449
BLAKE2b-256 88e1adfbcd0c4e417aa79d1ea720f223d16aae1e2439cdd96873762a9c81b142

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page