Request for Placeholder Replacement in Word Documents in python

Job ID: 38756401

Budget: €8 – €30 EUR

Development Request for Placeholder Replacement in Word Documents
Context:

We wish to develop a solution that allows for replacing placeholders in Word documents with values provided by a user, while preserving the document's formatting. This solution should be robust and capable of handling different types of placeholders.

Objectives:
Placeholder Detection:

Implement a function that scans a Word document to detect placeholders formatted in a specific way, such as:
[[employee name]]
[[postal code]]
[[*detailed description]] (for text fields)
[[Mr./Mrs.]] (for gender choices)
[[Option 1 | Option 2 | Option 3]] (for multiple selections)
Matching Placeholders with User Values:

Create a mechanism that associates each detected placeholder with the value provided by the user.
The matching function should take into account the type of placeholder:
For text fields, the user value will be directly used for replacement.
For gender choices, the code should determine which value to use based on the user's selection.
For multiple selections, the code should compare the user-selected value with the available options in the placeholder, preserving the original casing if an exact match is found.
Placeholder Replacement:

Develop a function that replaces these placeholders with the corresponding values provided by the user.
Ensure that the document's Word formatting remains unchanged after the placeholders are replaced. The complexity lies in preserving the document's style, including font, size, color, and other style attributes during text substitution.
The output should be a Word document saved in the .docx format containing the appropriate replacements.
Replacement Functionality:
Detection: The function begins by scanning the Word document to identify all the placeholders defined by the specified format.

Matching: Once the placeholders are detected, each placeholder will be associated with a user value:

For text fields: The text to be replaced is extracted from the user values.
For gender choices: The code will determine whether to choose the masculine or feminine value based on the user's selection.
For multiple selections: The code will compare user values with the options available in the placeholder and use the value that corresponds to the selection made by the user.
Replacement: The placeholders in the document will be replaced with the corresponding user values while preserving the original formatting of the text. The output will be a Word document saved as a .docx file.

Format of User Data:
User data will be provided in a dictionary as follows:

python
for example user input can be like name (or type) of th eplaceholders : { the value to replace } (label is for something else)
user_input = {
"address": {"value": "8 rue baradoc", "label": "Normal"},
"employee address": {"value": "9 rue baradocs", "label": "Normal"},
"postal code": {"value": "343434", "label": "Normal"},
"hire date": {"value": "October 29, 1998", "label": "Normal"},
"end date": {"value": "December 30", "label": "Normal"},
"detailed description": {"value": "a very long description huhr", "label": "Normal"},
"gender_1": {"value": "Masculine", "label": "Normal"},
"company name": {"value": "BARA DOC", "label": "Normal"},
"employee name": {"value": "Marco", "label": "Normal"},
"select_3": {"value": "option 1", "label": "Normal"},
"select_7": {"value": "telephone", "label": "Normal"}
}
Format of Placeholders:
Placeholders in the Word document should be formatted as follows:

Text Fields:

[[*detailed description]]
Gender Choices:

[[Mr./Mrs.]]
Multiple Selections:

[[Option 1 | Option 2 | Option 3]]
Simple Texts:

[[employee name]]
[[postal code]]
Expected Features:
Detection Function:

A function that detects placeholders in the document and classifies them by type (text, gender, selection, etc.).
Matching Function:

A function that associates each detected placeholder with its replacement value from user inputs.
Replacement Function:

A function that replaces the placeholders in the document with the associated values while preserving the original formatting.
Error Handling:

Handle cases where user values do not match the placeholders or are missing.
Documentation and Tests:

Provide clear documentation on the functionality of the functions.
Include unit tests to ensure the proper operation of each feature.
Related categories: Python Algorithm