| Crates.io | easy-docx-template |
| lib.rs | easy-docx-template |
| version | 0.1.1 |
| created_at | 2025-09-21 21:57:27.682103+00 |
| updated_at | 2025-09-22 15:19:16.04628+00 |
| description | create docx template |
| homepage | https://github.com/AltDemono/easy-docx-template-rs |
| repository | https://github.com/AltDemono/easy-docx-template-rs |
| max_upload_size | |
| id | 1849240 |
| size | 28,438 |
Create docx templates
Example 1:
fn main() {
// 1. Loading docx file
let mut docx = DOCX::new("example/test.docx".to_string());
docx.read();
// 2. Adding placeholders
docx.add_placeholder("{{exam.title}}", "Mathexam");
docx.add_placeholder("{{exam.variant}}", "1 variant");
docx.add_placeholder("{{exam.subject}}", "Math");
docx.add_placeholder("{{exam.level}}", "1-A form");
// 3. Init placeholders
docx.init_placeholders();
// 4. Save our docx file
docx.save("output.docx");
println!("✅ File saved: output.docx")
}
Example 2(Loading data from json):
fn main() {
// 1. Loading docx file
let mut docx = DOCX::new("example/test.docx".to_string());
docx.read();
// 2. Adding placeholders
docx.add_placeholders_from_json(r#"{
"exam": {
"level": "form 2-A",
"variant": "1 variant",
"title": "Math exam",
"subject": "math"
}
}"#);
// 3. Init placeholders
docx.init_placeholders();
// 4. Save our docx file
docx.save("output.docx");
println!("✅ File saved: output.docx")
}
Example 3(Add image placeholder)
fn test_1() {
// 1. Loading docx file
let mut docx = DOCX::new("example/test.docx".to_string());
docx.read();
// 2. Adding placeholders
docx.add_placeholders_from_json(r#"{
"exam": {
"level": "form 2-A",
"variant": "1 variant",
"title": "Math exam",
"subject": "math"
}
}"#);
// 4. Add image placeholder
docx.add_image_placeholder("image1.jpeg", "example/replace_image1.png");
// 5. Init placeholders
docx.init_placeholders();
// 6. Save our docx file
docx.save("output.docx");
println!("✅ File saved: output.docx")
}

Created by Dmitry Dzhugov
morfyalt@proton.me