Go to file
renovate[bot] 21811daf6f
chore(deps): update dependency jest to v27.0.5 (#306)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-06-23 18:38:14 +09:00
.github fix: read comment in ins (#222) 2021-01-06 20:31:53 +09:00
.vscode feat: Add table property 2019-11-12 18:02:50 +09:00
docs chore(deps): update dependency filesaver.js to v2.0.5 (#200) 2021-03-19 00:15:27 +09:00
docx-core Support vertalign (#302) 2021-06-08 00:10:44 +09:00
docx-wasm chore(deps): update dependency jest to v27.0.5 (#306) 2021-06-23 18:38:14 +09:00
fixtures Support vertalign (#302) 2021-06-08 00:10:44 +09:00
images Support image output (#69) 2020-05-14 12:01:20 +09:00
output Support default section header (#115) 2020-08-13 17:27:45 +09:00
vrt build(deps): bump lodash from 4.17.19 to 4.17.21 in /vrt (#290) 2021-06-02 13:07:12 +09:00
.gitignore Support vertalign (#302) 2021-06-08 00:10:44 +09:00
Cargo.lock chore(deps): update rust crate pretty_assertions to 0.7.2 (#278) 2021-04-26 11:03:15 +09:00
Cargo.toml clean wasm dir 2019-11-07 18:11:32 +09:00
LICENSE Create LICENSE (#30) 2020-01-31 01:48:26 +09:00
README.md Support text border (#257) 2021-03-21 00:16:43 +09:00
logo.png Add files via upload 2020-01-24 15:21:07 +09:00
makefile Support nest comment (#116) 2020-08-14 01:57:59 +09:00
renovate.json chore(deps): add renovate.json (#92) 2020-07-30 12:50:32 +09:00

README.md

A .docx file 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 { 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);

More examples

Features

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

Requirements

  • wasm-pack 0.9.1+