MCPcopy Index your code
hub / github.com/bokuweb/docx-rs

github.com/bokuweb/docx-rs @0.4.19

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.4.19 ↗ · + Follow
3,019 symbols 6,993 edges 560 files 55 documented · 2%

Browse by type

Functions 2,588 Types & classes 431
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

A .docx file `writer` with Rust/WebAssembly.

GitHub Actions Status docx-rs at crates.io

Installation

Rust

[dependencies]
docx-rs = "0.4"

Browser/Node.js

$ pnpm add docx-wasm

Example

Rust

use docx_rs::*;

pub fn hello() -> Result<(), DocxError> {
    let path = std::path::Path::new("./hello.docx");
    let file = std::fs::File::create(path).unwrap();
    Docx::new()
        .add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
        .build()
        .pack(file)?;
    Ok(())
}

Browser

import { saveAs } from "file-saver";

// // Note that a dynamic `import` statement here is required due to webpack/webpack#6615,
import("docx-wasm").then((w) => {
  const { buffer } = new w.Docx()
    .addParagraph(
      new w.Paragraph().addRun(new w.Run().addText("Hello world!!"))
    )
    .build();
  saveAs(new Blob([buffer]), "hello.docx");
});

Node.js

const w = require("docx-wasm");
const { writeFileSync } = require("fs");

const { buffer } = new w.Docx()
  .addParagraph(new w.Paragraph().addRun(new w.Run().addText("Hello world!!")))
  .build();

writeFileSync("hello.docx", Buffer.from(buffer));

More examples

Development

Requirements

  • Node.js 16+
  • pnpm 9+
  • wasm-pack0.10.1 (https://rustwasm.github.io/wasm-pack/)
  • insta (https://github.com/mitsuhiko/insta)

Examples

You can run example with following code. Please see examples directory.

$ cargo run --example [EXAMPLE_NAME]

For Example if you want to run hello example. Please run following command.

$ cargo run --example hello

So you can see output file in output directory.

Testing

Rust

Please run following command.

make lint && make test

If snapshot testing is failed, fix code or update snapshot files. (See https://insta.rs/).

$ cargo-insta review

Then re run test.

$ make test

Wasm

Please run following command.

$ cd docx-wasm && pnpm install && pnpm test

If snapshot testing is failed, fix code or update snapshot files. (See https://jestjs.io/docs/snapshot-testing).

$ pnpm test -- --updateSnapshot

Features

  • [x] Paragraph
  • [x] Alignment
  • [x] Indent
  • [x] Numbering
  • [x] Run
  • [x] Bold
  • [x] Size
  • [x] Font
  • [x] Color
  • [x] Highlight
  • [x] Underline
  • [x] vanish
  • [x] Italic
  • [x] TextBorder
  • [x] Footnote
  • [x] Break
  • [x] Header
  • [x] Footer
  • [x] Comment
  • [x] Image
  • [x] Style
  • [x] Table
  • [x] HIstory
  • [x] Table of contents
  • [ ] Section
  • [ ] Textbox

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Method 2,103
Function 485
Class 315
Enum 71
Interface 45

Languages

Rust83%
TypeScript17%

Modules by API surface

docx-core/src/documents/elements/paragraph.rs69 symbols
docx-core/src/documents/mod.rs67 symbols
docx-wasm/src/style.rs58 symbols
docx-core/src/documents/elements/style.rs50 symbols
docx-wasm/src/paragraph.rs49 symbols
docx-wasm/js/paragraph.ts47 symbols
docx-core/src/documents/elements/run.rs46 symbols
docx-wasm/js/index.ts44 symbols
docx-core/src/documents/elements/run_property.rs41 symbols
docx-wasm/src/doc.rs40 symbols
docx-wasm/js/run-property.ts39 symbols
docx-core/src/documents/elements/paragraph_property.rs39 symbols

For agents

$ claude mcp add docx-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page