Replace {placeholders} and manage content inside .docx files.
-
Primitive: not a template engine, but can do quite a few transformations
Replace text, swap images,delete comments,flip checkboxes, insert custom markup -
Fast: single-pass, avoids recompression, uses Aho-Corasick internally, almost O(n)
No long time read issues like docx-rs has -
Not memory-efficient (yet): operates on a byte stream without DOM tree allocation
Keeps the whole text in-memory
use docx_template::DocxFile;
use serde::Serialize;
use std::error::Error;
fn main() -> Result<(), Box<Error>> {
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 }
serde
(default) — usejson!
macro &Serialize
structs to create templatesdocx-rust
— insert markup defined by @cstkingkey/docx‑rustdocx-rs
— insert markup defined by @bokuweb/docx‑rs
name | description |
---|---|
@bokuweb/docx‑rs0.4.17 Apr 26, 2024 |
|
@cstkingkey/docx‑rust0.1.8 May 21, 2024 |
|
@yūdachi/docx1.1.2 (Apr 27, 2020) |
💀 (replaced by docx-rust) |
@kaisery/ooxmlsdk0.1.16 Oct 12, 2024 |
|
ooxml0.2.8 Nov 7, 2023 |
|
office-crypto | Allows decrypting password protected MS Office files |
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.