Go to file
bokuweb c89783e8d8
Improve toc writer2 (#389)
* fix: tab for toc

* fix:

* feat: Add paragraph.raw_text

* fix: improve toc item

* fix: toc item builder

* fix:

* fix

* feat: impl page ref for toc

* fix

* fix

* feat: Suppport hyperlink

* feat: Support alias

* feat: disable auto items

* feat: Add toc styles

* fix: clippy

* fix: test

* fix
2022-01-03 02:18:04 +09:00
.github Update ci.yml 2021-11-30 02:37:04 +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 Improve toc writer2 (#389) 2022-01-03 02:18:04 +09:00
docx-wasm Improve toc writer2 (#389) 2022-01-03 02:18:04 +09:00
fixtures Support strike (#390) 2021-12-21 11:54:27 +09:00
images Support image output (#69) 2020-05-14 12:01:20 +09:00
output Support taskpane settings (#311) 2021-06-30 22:37:13 +09:00
vrt chore(deps): update dependency libreoffice-convert to v1.3.3 (#352) 2021-10-20 15:04:56 +09:00
.gitignore Support vertalign (#302) 2021-06-08 00:10:44 +09:00
CHANGELOG.md 0.0.217 (#392) 2021-12-21 15:47:29 +09:00
CONTRIBUTING.md add contributing (#355) 2021-10-20 15:03:31 +09:00
Cargo.lock chore: 0.3.2 (#384) 2021-12-09 19:50:28 +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 fix: Add test and support table (#379) 2021-12-02 00:39:50 +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"

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