2.4 KiB
2.4 KiB
WordTemplateProcessor
This repository provides scripts for processing Word templates (.dotx) by searching and replacing specific text within headers, footers, or the main text body. It includes a setup script to ensure all necessary Python packages are installed.
Files
- setup_environment.py: This script checks if
pip
is installed, installs it if necessary, and then installs the required Python packages. - dotx_processor.py: This script processes
.dotx
files in a specified directory, replacing specified text in headers, footers, or the main text.
Requirements
- Python 3.x
- Microsoft Word installed
- Internet connection to install packages
Usage
-
Setup the Environment:
Run the
setup_environment.py
script to ensurepip
and required packages are installed:py setup_environment.py
2. **Run the Processor Script:**
Execute the `dotx_processor.py` script to process Word templates:
```bash
py dotx_processor.py
```
3. **Follow the Prompts:**
The script will prompt you for the following inputs:
- **Path to the input directory**: Enter the path where your `.dotx` files are located.
- **Path to the output directory**: Enter the path where you want the modified files to be saved.
- **Area for text replacement**: Choose where to replace the text (`Header`, `Footer`, or `Text`).
- **Text to find**: Enter the exact text string you want to search for in the documents.
- **Text to replace with**: Enter the new text string that will replace the found text.
## Example Usage
1. Run the setup script to ensure the environment is prepared:
py setup_environment.py
This command will install `pip` if it is not already installed and then use it to install the necessary Python packages (`pywin32`).
2. Run the processing script to start modifying your `.dotx` files:
py dotx_processor.py
After running this command, follow the on-screen prompts to specify the directories and text replacement details.
## Notes
- Ensure that Word documents are not open in other applications while running the script to avoid file access issues.
- The output directory must have write permissions for the modified files to be saved correctly.
- Use absolute paths for the input and output directories to avoid path resolution issues.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.