WordTemplateProcessor/README.md

68 lines
2.4 KiB
Markdown
Raw Normal View History

2024-08-30 08:43:07 +00:00
# WordTemplateProcessor
2024-08-30 08:51:16 +00:00
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
1. **Setup the Environment:**
Run the `setup_environment.py` script to ensure `pip` and required packages are installed:
2024-08-30 08:58:51 +00:00
2024-08-30 08:59:20 +00:00
```bash
2024-08-30 08:59:36 +00:00
py setup_environment.py
2024-08-30 08:56:31 +00:00
2024-08-30 08:51:16 +00:00
2. **Run the Processor Script:**
2024-08-30 08:55:08 +00:00
Execute the `dotx_processor.py` script to process Word templates:
2024-08-30 08:58:51 +00:00
2024-08-30 08:59:20 +00:00
```bash
2024-08-30 08:59:36 +00:00
py dotx_processor.py
2024-08-30 08:51:16 +00:00
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:
2024-08-30 08:58:51 +00:00
2024-08-30 08:59:20 +00:00
```bash
2024-08-30 08:59:36 +00:00
py setup_environment.py
2024-08-30 08:51:16 +00:00
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:
2024-08-30 08:58:51 +00:00
2024-08-30 08:59:20 +00:00
```bash
2024-08-30 08:59:36 +00:00
py dotx_processor.py
2024-08-30 08:51:16 +00:00
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.