Go to file
dependabot[bot] f8c84a2e5e
build(deps): bump ws from 6.2.2 to 6.2.3 in /docx-wasm (#723)
Bumps [ws](https://github.com/websockets/ws) from 6.2.2 to 6.2.3.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/compare/6.2.2...6.2.3)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-22 09:11:20 +09:00
.github docs: fontsize example (#441) 2022-03-11 11:35:56 +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 page numbers (#714) 2024-06-09 09:01:52 +09:00
docx-wasm build(deps): bump ws from 6.2.2 to 6.2.3 in /docx-wasm (#723) 2024-06-22 09:11:20 +09:00
fixtures Add sdt in header footer (#683) 2024-03-05 11:14:49 +09:00
images Support image output (#69) 2020-05-14 12:01:20 +09:00
output feat: Support styleWithLevels (#403) 2022-01-11 00:39:38 +09:00
vrt build(deps): bump minimatch from 3.0.4 to 3.1.2 in /vrt (#579) 2022-12-13 13:34:47 +09:00
.gitignore feat: improve pic reader (#456) 2022-03-28 19:40:32 +09:00
CHANGELOG.md 0.4.17 (#711) 2024-04-26 18:33:16 +09:00
CONTRIBUTING.md add contributing (#355) 2021-10-20 15:03:31 +09:00
Cargo.lock 0.4.17 (#711) 2024-04-26 18:33:16 +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 Update README.md 2024-04-21 20:34:03 +09:00
hello.docx fix: del in ins (#442) 2022-03-15 16:58:29 +09:00
hello.json Support image in header footer (#680) 2024-02-19 18:11:07 +09:00
image.docx Fix anchor (#459) 2022-03-29 17:56:49 +09:00
logo.png Add files via upload 2020-01-24 15:21:07 +09:00
makefile feat: improve pic reader (#456) 2022-03-28 19:40:32 +09:00
renovate.json chore(deps): add renovate.json (#92) 2020-07-30 12:50:32 +09:00
rust-toolchain Support tblppr (#693) 2024-03-27 00:09:58 +09:00
yarn.lock fix: escape hyperlink (#556) 2022-10-31 15:27:34 +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.4"

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

Development

Requirements

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 && yarn install && yarn test

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

$ yarn test -- --updateSnapshot

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
  • Textbox