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.1.tar.gz (23.3 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.1-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wordreplaceengine-1.0.1.tar.gz
  • Upload date:
  • Size: 23.3 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.1.tar.gz
Algorithm Hash digest
SHA256 1792693e5bb7246351ef49e1186a8e2bd0c8831dedb4f8d712d063152e1ef8f6
MD5 d2a8cf08691d59437474305a6749c390
BLAKE2b-256 3ebfcd28e38c546ed3056079d06f6ddb90a47e2c06b43fcaccd9c958bffebf26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for wordreplaceengine-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2ff5d16c425f77fab264b293c0606adf5985887ffe5c3f9c46725af8c918d381
MD5 501ca53f727c2f1636d50c794ea34d07
BLAKE2b-256 0be90535938661aac3fb1648b5be6519dee5d0b9182d0e4539c7cc9c4f413a19

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