> {
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 | - DOM tree contains _owned_ values
- User-friendly naming and structure
- Reference ids must be set manually, despite automatic increments
- π₯ Lots of examples
docx-template = { feature = ["docx-rs"] } |
| @cstkingkey/[docx‑rust](https://lib.rs/crates/docx-rust)
`0.1.8`
May 21, 2024 | - DOM tree has a _\'lifetime_ parameter
- Close-to-spec naming and structure
- Reference ids must be set manually
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 | - Inspired by .NET [Open XML SDK](https://github.com/dotnet/Open-XML-SDK)
- Low-level, generated from specification
- Early development stage
|
| | |
| [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.