Skip to content
/ docx-rs Public
forked from bokuweb/docx-rs

📝 A .docx file reader/writer with Rust/WebAssembly.

License

Notifications You must be signed in to change notification settings

nottxy/docx-rs

 
 

Repository files navigation

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


GitHub Actions Status docx-rs at crates.io

Installation

Rust

[dependencies]
docx-rs = "0.2.0"

Browser/Node.js

yarn 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 buf = new w.Docx()
    .addParagraph(
      new w.Paragraph().addRun(new w.Run().addText("Hello world!!"))
    )
    .build();
  saveAs(new Blob([buf]), "hello.docx");
});

Node.js

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

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

writeFileSync("hello.docx", buf);

More examples

Features

  • Paragraph
  • Alignment
  • Indent
  • Numbering
  • Run
  • Bold
  • Size
  • Color
  • Highlight
  • Underline
  • vanish
  • Italic
  • Break
  • Header
  • Footer
  • Comment
  • Image
  • Style
  • Table
  • HIstory
  • Table of contents
  • Section

Requirements

  • wasm-pack 0.9.1+

About

📝 A .docx file reader/writer with Rust/WebAssembly.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 92.8%
  • TypeScript 6.2%
  • Other 1.0%