Skip to main content

A Python engine for automated word replacement in Word documents

Project description

WordReplaceEngine

WordReplaceEngine is a library for quickly replacing text in word. Developers only need to write the replacement logic in their program, and subsequent changes to the Word format do not require modifications to the program itself.

Language:

Usage Instructions

(1a) If you are referencing directly from GitHub, please enter the following in pip:

pip install git+https://github.com/orztrickster/WordReplaceEngine.git

(1b) If you are referencing from PyPI, please enter the following in pip:

pip install WordReplaceEngine

(2) Next, define the following at the beginning of the program:

from WordReplaceEngine import Document

(3) Create an object:

document = Document()

(4) Enter the word file to be modified. You can pre-enter the paths of all possible word files and specify the name when you need to modify them later. Here, we will arbitrarily name them word_001 to word_004. Please modify them according to your actual needs:

document.set_word_version_path("word_001", "C:/WordReplaceEngine/word_001.docx")
document.set_word_version_path("word_002", "C:/WordReplaceEngine/word_002.docx")
document.set_word_version_path("word_003", "C:/WordReplaceEngine/word_003.docx")
document.set_word_version_path("word_004", "C:/WordReplaceEngine/word_004.docx")

(5) Specify the name of the word file to be modified next, where save_path represents the storage path

document.run_version("word_001", save_path = "C:/WordReplaceEngine/")

(6a) Next, specify the corresponding string to be replaced in the word file. Here, replace $$$WordReplaceEngine_001$$$ in the word file with Hello World

document.set("$$$WordReplaceEngine_001$$$", "Hello World")

(6b) You can also specify the text size and position

from docx.shared import Pt
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
document.set("$$$WordReplaceEngine_002$$$", "Hello WordReplaceEngine!", new_alignment = WD_PARAGRAPH_ALIGNMENT.LEFT, new_font_size = Pt(20))

(6c) You can also specify whether the text is bold, the font of Chinese or English, and the color

document.set("$$$WordReplaceEngine_003$$$", "Hello WordReplaceEngine!!!", bold = True, new_font_name = "Microsoft JhengHei", new_font_name_Chinese = "Microsoft JhengHei", font_color=(192, 0, 0))

(7) After all the information has been entered, please execute execute_set to apply the settings

document.execute_set()

(8) Next, enter output to output the file. The output file will be located in C:/WordReplaceEngine/ as specified in the example above

document.output("WordReplaceEngine", pdf = False, docx = True)

(9) Finally, please enter delete to clear the settings you just applied, and then you can return to step (5) to repeat the modification of other files.

document.delete()

Licensing

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) by default.

An alternative MIT License is available under the following conditions:

  1. The user has completed a remittance of any amount to the bank account specified in: docs/Inward-remittance-instruction2025.11

  2. The user has sent a notification email to: startime_electronics@orztrickster.com for record-keeping purposes only.

Upon fulfillment of the above conditions, the user is automatically granted a separate MIT License for this project.

No explicit confirmation or reply from the author is required for the MIT License to take effect. The completion of the remittance (regardless of amount) and the sending of the notification email constitute acceptance and fulfillment of the licensing conditions.

The full text of the MIT License applicable under these conditions is provided in the following file for reference: docs/LICENSE_MIT

In the event of any dispute, the user bears the burden of proving that both the remittance and the notification email have been completed.

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

wordreplaceengine-1.0.0.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

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

wordreplaceengine-1.0.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file wordreplaceengine-1.0.0.tar.gz.

File metadata

  • Download URL: wordreplaceengine-1.0.0.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for wordreplaceengine-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e2618400a692837e784703760e41c6ab2aadc569fa5627fd72e9ec2a611053ae
MD5 2d021e106742b5e22974de2bffe7bb8e
BLAKE2b-256 47286094178ff69615c24930d8229f1658738fe85e33ffc820023af96639749a

See more details on using hashes here.

File details

Details for the file wordreplaceengine-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wordreplaceengine-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbd7795b60147663ed7db475d4ba342f7a8e22b5cb2fc03d9722eedd46723fde
MD5 3b896ef34d7ad817178591b5cc72eb4f
BLAKE2b-256 e1a9ef7827a6127f976d85b0ddb6300ac83e6284a309b6dc442e56a1ffc2e2be

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