Getting started
Install and write a document
Choose a language to write report.docx.
In a Cargo project with Rust 1.88 or newer:
cargo add rocx
resolve() is async. If your app already uses Tokio or another async runtime, call write_report().await there. For a standalone executable with a synchronous main, run cargo add futures-executor for the block_on call below.
Save as src/main.rs and run cargo run:
use rocx::{Document, Error, Paragraph, Section};
async fn write_report() -> Result<(), Error> {
let section = Section::new(vec![Paragraph::new("Hello, world!").into()]);
Document::new(vec![section.into()]).resolve().await?.save("report.docx")
}
fn main() -> Result<(), Error> {
futures_executor::block_on(write_report())
}
In a CPython 3.12 or newer environment:
python -m pip install rocx
A compatible prebuilt wheel does not require a Rust toolchain; building
the extension from source does. Save this as report.py and run
python report.py:
import asyncio
from rocx import declarative as d
async def main():
document = d.Document([d.Section(children=[d.Paragraph(text="Hello, world!")])])
await document.save("report.docx")
asyncio.run(main())
Run npm install rocx-docx in your Node.js project.
Save this as report.mjs and run node report.mjs:
import { writeFile } from "node:fs/promises";
import { declarative as d, generateDocx } from "rocx-docx";
const document = d.Document([d.Section([
d.Paragraph("Hello, world!"),
])]);
await writeFile("report.docx", await generateDocx(document));
Open report.docx in your document viewer. Next, try filling a template or browse the visual catalog.