docxedit


Namedocxedit JSON
Version 1.0.4 PyPI version JSON
download
home_pageNone
SummaryEdit Word documents but keep original formatting
upload_time2024-09-04 22:57:28
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords document docx edit formatting python-docx word
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Mass Edit Word Documents Without Changing the Original Formatting

Edit Word documents effortlessly and without changing the original formatting of the document. 

The original `docx` library is great but it's missing one important feature: *keeping the original formatting*.

However, this functionality is pretty useful if you want to automate document writing or editing and need to adhere to strict formatting rules. This is a common requirement in corporate environments for example.

This module adds that feature with some functions that allow editing documents without changing the original formatting.

[![PyPI version](https://badge.fury.io/py/docxedit.svg)](https://badge.fury.io/py/docxedit)

## Install

With pip: `pip install docxedit`

## Dependencies

Included as a dependency: `python-docx` (`docx`)

## Functionalities
Most of the functions in this module work primarily with **runs**, which are sequences of strings with the same formatting style. Breaking the document into runs allows us to edit the text without changing the original formatting.

Some of the functionalities that this module include:
- Replacing all occurrences of a string with a new string (optionally limit this up to a paragraph number, and include or exclude tables)
- Removing a line that includes a specific string
- Add text to a table

The beauty of this module is that you can use all of its functions to **mass edit** Word documents with consistency and precision. This is useful especially in corporate environments where a lot of document writing or editing can be automated. 


## How to Use

Usage of this module is really simple. Here are some examples:

```python
from docx import Document
import docxedit

document = Document('path/to/your/document.docx')

# Replace all instances of the word 'Hello' in the document with 'Goodbye' (including tables)
docxedit.replace_string(document, old_string='Hello', new_string='Goodbye')

# Replace all instances of the word 'Hello' in the document with 'Goodbye' but only
# up to paragraph 10
docxedit.replace_string_up_to_paragraph(document, old_string='Hello', new_string='Goodbye', 
                                        paragraph_number=10)

# Remove any line that contains the word 'Hello' along with the next 5 lines after that
docxedit.remove_lines(document, first_line='Hello', number_of_lines=5)

# Add text in a table cell (row 1, column 1) in the first table in the document
docxedit.add_text_in_table(document.tables[0], row_num=1, column_num=1, new_string='Hello')

# Save the document
document.save('path/to/your/edited/document.docx')
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "docxedit",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "document, docx, edit, formatting, python-docx, word",
    "author": null,
    "author_email": "Henri Happonen <henkka.happonen@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/d8/8d/d21146615ba13cd5cd764b2f87063eb738a68a9980e6d386cf46781cef3c/docxedit-1.0.4.tar.gz",
    "platform": null,
    "description": "# Mass Edit Word Documents Without Changing the Original Formatting\n\nEdit Word documents effortlessly and without changing the original formatting of the document. \n\nThe original `docx` library is great but it's missing one important feature: *keeping the original formatting*.\n\nHowever, this functionality is pretty useful if you want to automate document writing or editing and need to adhere to strict formatting rules. This is a common requirement in corporate environments for example.\n\nThis module adds that feature with some functions that allow editing documents without changing the original formatting.\n\n[![PyPI version](https://badge.fury.io/py/docxedit.svg)](https://badge.fury.io/py/docxedit)\n\n## Install\n\nWith pip: `pip install docxedit`\n\n## Dependencies\n\nIncluded as a dependency: `python-docx` (`docx`)\n\n## Functionalities\nMost of the functions in this module work primarily with **runs**, which are sequences of strings with the same formatting style. Breaking the document into runs allows us to edit the text without changing the original formatting.\n\nSome of the functionalities that this module include:\n- Replacing all occurrences of a string with a new string (optionally limit this up to a paragraph number, and include or exclude tables)\n- Removing a line that includes a specific string\n- Add text to a table\n\nThe beauty of this module is that you can use all of its functions to **mass edit** Word documents with consistency and precision. This is useful especially in corporate environments where a lot of document writing or editing can be automated. \n\n\n## How to Use\n\nUsage of this module is really simple. Here are some examples:\n\n```python\nfrom docx import Document\nimport docxedit\n\ndocument = Document('path/to/your/document.docx')\n\n# Replace all instances of the word 'Hello' in the document with 'Goodbye' (including tables)\ndocxedit.replace_string(document, old_string='Hello', new_string='Goodbye')\n\n# Replace all instances of the word 'Hello' in the document with 'Goodbye' but only\n# up to paragraph 10\ndocxedit.replace_string_up_to_paragraph(document, old_string='Hello', new_string='Goodbye', \n                                        paragraph_number=10)\n\n# Remove any line that contains the word 'Hello' along with the next 5 lines after that\ndocxedit.remove_lines(document, first_line='Hello', number_of_lines=5)\n\n# Add text in a table cell (row 1, column 1) in the first table in the document\ndocxedit.add_text_in_table(document.tables[0], row_num=1, column_num=1, new_string='Hello')\n\n# Save the document\ndocument.save('path/to/your/edited/document.docx')\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Edit Word documents but keep original formatting",
    "version": "1.0.4",
    "project_urls": {
        "Bug Tracker": "https://github.com/henrihapponen/docxedit/issues",
        "Homepage": "https://github.com/henrihapponen/docxedit"
    },
    "split_keywords": [
        "document",
        " docx",
        " edit",
        " formatting",
        " python-docx",
        " word"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "739290f07834bffff592d43adc205bb9d0438ef78876a8c7471dd70c19efcb8e",
                "md5": "3fc77dfe5de2209fb67971922ca667a7",
                "sha256": "e98383e27c5f19b0fd77b9251f3856d07808a01ceec7338ec255a03ac4d85d75"
            },
            "downloads": -1,
            "filename": "docxedit-1.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3fc77dfe5de2209fb67971922ca667a7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4772,
            "upload_time": "2024-09-04T22:57:27",
            "upload_time_iso_8601": "2024-09-04T22:57:27.023633Z",
            "url": "https://files.pythonhosted.org/packages/73/92/90f07834bffff592d43adc205bb9d0438ef78876a8c7471dd70c19efcb8e/docxedit-1.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d88dd21146615ba13cd5cd764b2f87063eb738a68a9980e6d386cf46781cef3c",
                "md5": "db7dcaed1d067963c225a37b4b388e22",
                "sha256": "37def541044495a7a1f232fbf2e10e4befd3d03baab1b0178abe3066b7d58c36"
            },
            "downloads": -1,
            "filename": "docxedit-1.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "db7dcaed1d067963c225a37b4b388e22",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5506,
            "upload_time": "2024-09-04T22:57:28",
            "upload_time_iso_8601": "2024-09-04T22:57:28.443607Z",
            "url": "https://files.pythonhosted.org/packages/d8/8d/d21146615ba13cd5cd764b2f87063eb738a68a9980e6d386cf46781cef3c/docxedit-1.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-04 22:57:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "henrihapponen",
    "github_project": "docxedit",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "docxedit"
}
        
Elapsed time: 0.62089s