This Node.js script uses PizZip and Docxtemplater to load a .docx
file, populate it with dynamic data, and generate a new .docx
document based on the provided template and data.
- Loads a
.docx
file from the filesystem. - Fills the template with dynamic data.
- Supports Persian (Farsi) date and string formatting.
- Exports the modified document as a new
.docx
file.
- Node.js
- PizZip (for handling
.docx
files) - Docxtemplater
-
Clone the repository:
git clone https://github.com/yourusername/repo-name.git cd repo-name
-
Install the dependencies:
npm install
-
Place your template file (
input.docx
) in the root directory. -
Modify the data in the
dataObject
as needed. This object contains all the values that will be replaced in the template. -
Run the script:
node script.js
-
The new document will be generated as
output.docx
in the same directory.
Here is an example of the data populated into the template:
{
"NetworkAreaName": "معاونت صدا",
"NetworkName": "شبکه جوان (صدا)",
"ReleaseDate": "2024-01-15",
"content": "بیان مطلب بی اساس مجری...",
"SupervisorFullName": "آمنه سادات احمدی",
"start": "22:11:32",
"end": "22:12:33"
}
The script also:
- Converts Gregorian dates to Persian (Farsi).
- Removes seconds and milliseconds from time strings.
A new .docx
file, output.docx
, will be generated with the populated data.