{"id":16764652,"url":"https://github.com/xamgore/docx-template","last_synced_at":"2025-08-02T01:36:13.368Z","repository":{"id":247133637,"uuid":"818629267","full_name":"xamgore/docx-template","owner":"xamgore","description":"Replace {placeholders} and manage content inside .docx files","archived":false,"fork":false,"pushed_at":"2024-11-04T13:09:37.000Z","size":3110,"stargazers_count":5,"open_issues_count":9,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-04T14:17:59.936Z","etag":null,"topics":["docx","microsoft-word","template"],"latest_commit_sha":null,"homepage":"https://docs.rs/crate/docx-template","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xamgore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-22T11:39:24.000Z","updated_at":"2024-11-04T13:09:40.000Z","dependencies_parsed_at":"2024-09-10T15:03:00.385Z","dependency_job_id":"bbb1bc36-cd41-4d7c-b633-875924d0bd99","html_url":"https://github.com/xamgore/docx-template","commit_stats":null,"previous_names":["xamgore/docx-template"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xamgore%2Fdocx-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xamgore%2Fdocx-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xamgore%2Fdocx-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xamgore%2Fdocx-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xamgore","download_url":"https://codeload.github.com/xamgore/docx-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225886220,"owners_count":17539770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docx","microsoft-word","template"],"created_at":"2024-10-13T05:26:43.275Z","updated_at":"2024-11-22T11:19:13.130Z","avatar_url":"https://github.com/xamgore.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# docx-template [![](https://img.shields.io/crates/v/docx-template.svg)](https://crates.io/crates/docx-template) [![](https://docs.rs/docx-template/badge.svg)](https://docs.rs/docx-template/)\n\nReplace {placeholders} and manage content inside .docx files.\n\n---\n\n\u003cimg src=\"https://raw.githubusercontent.com/xamgore/docx-template/master/.github/assets/logo.svg\" width=\"420\" alt=\"Dear {crustacean}, → Dear 🦀,\"\u003e\n\n---\n\n- **Primitive**: not a template engine, but can do quite a few transformations\n  \u003cbr\u003e\u003csup\u003e[Replace text](#), [swap images](#), [~~delete comments~~](#), [~~flip\n  checkboxes~~](https://github.com/xamgore/docx-template/issues/6), [insert custom markup](https://github.com/xamgore/docx-template/issues/3)\u003c/sup\u003e\n\n- **Fast**: single-pass, avoids recompression, uses Aho-Corasick internally, almost O(n)\n  \u003cbr\u003e\u003csup\u003eNo [long time read issues](https://github.com/bokuweb/docx-rs/issues/757) like docx\u0026#x2011;rs has\u003c/sup\u003e\n\n- **Not memory-efficient (yet)**: operates on a byte stream without DOM tree allocation\n  \u003cbr\u003e\u003csup\u003eKeeps the whole text in\u0026#x2011;memory\u003c/sup\u003e\n\n### Example\n\n```rust\nuse docx_template::DocxFile;\nuse serde::Serialize;\nuse std::error::Error;\n\nfn main() -\u003e Result\u003c(), Box\u003cError\u003e\u003e {\n    let data = Data { crustacean: \"🦀\".into() };\n    let output = DocxFile::from_path(\"in.docx\")?.into_template(data)?.render()?;\n    std::fs::write(\"output.docx\", output)?;\n    Ok(())\n}\n\n#[derive(Serialize)]\nstruct Data {\n    crustacean: String\n}\n```\n\n### Why\n\nA naive approach to the problem is just calling `xml.replace(\"{placeholder}\", \"🦀\")`.\nWhich isn't 100% accurate, as placeholders can reside in multiple adjacent XML nodes like in the example below.\nThat's why this crate was made. It reads XML nodes, detects patterns, and applies transformations keeping the structural integrity.\n\n```xml\n\u003cw:run\u003e{place\u003c/w:run\u003e\u003cw:run\u003eholder}\u003c/w:run\u003e\n\u003cw:run\u003e🦀\u003c/w:run\u003e\u003cw:run\u003e\u003c/w:run\u003e\n```\n\n### Features\n\n- `serde` (default) — use `json!` macro \u0026 `Serialize` structs to create templates\n- `docx-rs` — insert markup defined by @bokuweb/[docx\u0026#x2011;rs](https://lib.rs/crates/docx-rs)\n- `docx-rust` — insert markup defined by @cstkingkey/[docx\u0026#x2011;rust](https://lib.rs/crates/docx-rust)\n\n### Ecosystem\n\n|                                                 name                                                  | description                                                                                                                                                                                                                                                                                                                                      |\n|:-----------------------------------------------------------------------------------------------------:|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n|    @bokuweb/[docx\u0026#x2011;rs](https://lib.rs/crates/docx-rs)\u003cbr\u003e`0.4.18`\u003cbr\u003e\u003csup\u003eApr 26, 2024\u003c/sup\u003e    | \u003cul\u003e\u003cli\u003eDOM tree contains _owned_ values\u003c/li\u003e\u003cli\u003eUser-friendly naming and structure\u003c/li\u003e\u003cli\u003eReference ids must be set manually, despite automatic increments\u003c/li\u003e\u003cli\u003e🔥 Lots of \u003ca href=\"https://github.com/bokuweb/docx-rs/tree/main/docx-core/examples\"\u003eexamples\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e\u003cpre lang=\"rust\"\u003edocx-template = { feature = [\"docx-rs\"] }\u003c/pre\u003e |\n| @cstkingkey/[docx\u0026#x2011;rust](https://lib.rs/crates/docx-rust)\u003cbr\u003e`0.1.8`\u003cbr\u003e\u003csup\u003eMay 21, 2024\u003c/sup\u003e | \u003cul\u003e\u003cli\u003eDOM tree has a _\\'lifetime_ parameter\u003c/li\u003e\u003cli\u003eClose-to-spec naming and structure\u003c/li\u003e\u003cli\u003eReference ids must be set manually\u003c/li\u003e\u003c/ul\u003e\u003cpre lang=\"rust\"\u003edocx-template = { feature = [\"docx-rust\"] }\u003c/pre\u003e                                                                                                                                  |\n|           @yūdachi/[docx](https://lib.rs/crates/docx)\u003cbr\u003e`1.1.2`\u003cbr\u003e\u003csup\u003eApr 27, 2020\u003c/sup\u003e           | 💀 (forked by docx-rust)                                                                                                                                                                                                                                                                                                                         |\n|                                                                                                       |                                                                                                                                                                                                                                                                                                                                                  |\n|      @kaisery/[ooxmlsdk](https://lib.rs/crates/ooxmlsdk)\u003cbr\u003e`0.1.16`\u003cbr\u003e\u003csup\u003eOct 12, 2024\u003c/sup\u003e       | \u003cul\u003e\u003cli\u003eInspired by .NET [Open XML SDK](https://github.com/dotnet/Open-XML-SDK)\u003c/li\u003e\u003cli\u003eLow-level, generated from specification\u003c/li\u003e\u003cli\u003eEarly development stage\u003c/ul\u003e                                                                                                                                                                             |\n|                                                                                                       |                                                                                                                                                                                                                                                                                                                                                  |\n|                         [office-crypto](https://lib.rs/crates/office-crypto)                          | Allows decrypting password protected MS Office files                                                                                                                                                                                                                                                                                             |\n|                   [ms-offcrypto-writer](https://lib.rs/crates/ms-offcrypto-writer)                    | Encrypting ECMA376/OOXML files with agile encryption                                                                                                                                                                                                                                                                                             |\n\n\u003e [!NOTE]\n\u003e Office Open XML (also informally known as OOXML or Microsoft Open XML (MOX)) is a zipped, XML-based file format\n\u003e developed by Microsoft for representing spreadsheets, charts, presentations and word processing documents. The format\n\u003e was initially standardized by Ecma (as ECMA-376), and by the ISO and IEC (as ISO/IEC 29500) in later versions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxamgore%2Fdocx-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxamgore%2Fdocx-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxamgore%2Fdocx-template/lists"}