# docx-template **Repository Path**: qianrw/docx-template ## Basic Information - **Project Name**: docx-template - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-12 - **Last Updated**: 2025-12-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## 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/) Replace {placeholders} and manage content inside .docx files. --- Dear {crustacean}, β†’ Dear πŸ¦€, --- - **Primitive**: not a template engine, but can do quite a few transformations
[Replace text](#), [swap images](#), [~~delete comments~~](#), [~~flip checkboxes~~](https://github.com/xamgore/docx-template/issues/6), [insert custom markup](https://github.com/xamgore/docx-template/issues/3) - **Fast**: single-pass, avoids recompression, uses Aho-Corasick internally, almost O(n)
No [long time read issues](https://github.com/bokuweb/docx-rs/issues/757) like docx‑rs has - **Not memory-efficient (yet)**: operates on a byte stream without DOM tree allocation
Keeps the whole text in‑memory ### Example ```rust use docx_template::DocxFile; use serde::Serialize; use std::error::Error; fn main() -> Result<(), Box> { let data = Data { crustacean: "πŸ¦€".into() }; let output = DocxFile::from_path("in.docx")?.into_template(data)?.render()?; std::fs::write("output.docx", output)?; Ok(()) } #[derive(Serialize)] struct Data { crustacean: String } ``` ### Why A naive approach to the problem is just calling `xml.replace("{placeholder}", "πŸ¦€")`. Which isn't 100% accurate, as placeholders can reside in multiple adjacent XML nodes like in the example below. That's why this crate was made. It reads XML nodes, detects patterns, and applies transformations keeping the structural integrity. ```xml {placeholder} πŸ¦€ ``` ### Features - `serde` (default) β€” use `json!` macro & `Serialize` structs to create templates - `docx-rs` β€” insert markup defined by @bokuweb/[docx‑rs](https://lib.rs/crates/docx-rs) - `docx-rust` β€” insert markup defined by @cstkingkey/[docx‑rust](https://lib.rs/crates/docx-rust) ### Ecosystem | name | description | |:-----------------------------------------------------------------------------------------------------:|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | @bokuweb/[docx‑rs](https://lib.rs/crates/docx-rs)
`0.4.18`
Apr 26, 2024 |
docx-template = { feature = ["docx-rs"] }
| | @cstkingkey/[docx‑rust](https://lib.rs/crates/docx-rust)
`0.1.8`
May 21, 2024 |
docx-template = { feature = ["docx-rust"] }
| | @yΕ«dachi/[docx](https://lib.rs/crates/docx)
`1.1.2`
Apr 27, 2020 | πŸ’€ (forked by docx-rust) | | | | | @kaisery/[ooxmlsdk](https://lib.rs/crates/ooxmlsdk)
`0.1.16`
Oct 12, 2024 | | | | | | [office-crypto](https://lib.rs/crates/office-crypto) | Allows decrypting password protected MS Office files | | [ms-offcrypto-writer](https://lib.rs/crates/ms-offcrypto-writer) | Encrypting ECMA376/OOXML files with agile encryption | > [!NOTE] > Office Open XML (also informally known as OOXML or Microsoft Open XML (MOX)) is a zipped, XML-based file format > developed by Microsoft for representing spreadsheets, charts, presentations and word processing documents. The format > was initially standardized by Ecma (as ECMA-376), and by the ISO and IEC (as ISO/IEC 29500) in later versions.