• Stars
    star
    335
  • Rank 125,904 (Top 3 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📝 A .docx file writer with Rust/WebAssembly.

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

More Repositories

1

react-rnd

🖱 A resizable and draggable component for React.
TypeScript
3,417
star
2

re-resizable

📏 A resizable component for React.
TypeScript
2,166
star
3

react-sortable-pane

✨ A sortable and resizable pane component for React.
TypeScript
635
star
4

rustynes

👾 An NES emulator by Rust and WebAssembly
Rust
473
star
5

re-bulma

[Deprecated] 💎Bulma components for React
JavaScript
364
star
6

gopher-boy

🎮 A Game Boy emulator written in Go
Go
244
star
7

flownes

🎮 An NES emulator written in ES2015+ with flowtype
JavaScript
170
star
8

zstd-wasm

Zstandard for browser, Node.js and Deno
TypeScript
108
star
9

r2

A RISC-V emulator written in Rust 🦀
Rust
100
star
10

lcs-image-diff-rs

🖼 Image diff tool with LCS algorithm
Rust
83
star
11

slack-list-ja

📋 A handpicked selection of top Slack communities in japan
CSS
78
star
12

Tsukiakari

【WIP】Twitter Client built on Electron.
JavaScript
64
star
13

lifegameboy

🦀 Conway's Game of Life written in Rust on GameBoyAdvance
Rust
54
star
14

yaw

🦀 A wasm interpreter in Rust
Rust
53
star
15

karma-nightmare

⚡ A Karma plugin. Launcher for Nightmare
JavaScript
52
star
16

slate-editable-table

🖊️ An editable table plugin for Slate.js
TypeScript
44
star
17

rust-wasm-game-of-life

👾 Conway's Game of Life written by Rust with WebAssembly
Rust
41
star
18

tuna_pasta

[Deprecated] Hatena Bookmark Viwer, build with React/Redux, focused on keyword.
JavaScript
38
star
19

bmsjs

browser bms player project.
CoffeeScript
35
star
20

ithildin

Twitter Client built on Electron with Mithril.js
CoffeeScript
28
star
21

deno-pretty-assert

🦕A colorful assertEqual for deno
TypeScript
26
star
22

avaron

🚀 AVA + Electron :electron: = Avaron
JavaScript
22
star
23

react-tutorial-with-redux

react tutorial with redux
JavaScript
21
star
24

github-image-diff

🚧 [Deprecated] :octocat: A chrome extension to check github image difference.
JavaScript
19
star
25

nes-sprites2png

👾 convert nes sprites to png
JavaScript
18
star
26

wu-diff-js

Compute differences between two slices using wu(the O(NP)) algorithm.
TypeScript
17
star
27

node-lcs-img-diff

🖼 Image diff tool with LCS algorithm for Node.js
Rust
14
star
28

react-native-universal-modal

Universal simple modal component for React Native
JavaScript
14
star
29

vscode-git-grep

Git grep extension for Visual Studio Code
TypeScript
13
star
30

rxjs-tetris

DOM based rxjs tetris
TypeScript
13
star
31

image-diff-rs

This project provides an image differencing library that supports PNG,JPEG,GIF,TIFF,and WebP formats for Node.js, Deno, and Rust.
JavaScript
13
star
32

app.flavabeats

browser music game for PC
JavaScript
12
star
33

json-schema-to-flowtype-cli

JSON Schema to flowtype cli.
JavaScript
11
star
34

zig-os-in-1000-lines

Zig
10
star
35

pixelmatch-rs

port of mapbox/pixelmatch
JavaScript
9
star
36

react-resizable-decorator

[Deprecated] Resizable decorator for React component.
JavaScript
9
star
37

vscode-ripgrep

A ripgrep extension for Visual Studio Code
TypeScript
9
star
38

react-blog-sample

Blog system sample on Node.js, Express.js, MongoDB and React.js
CoffeeScript
8
star
39

r2v

[WIP] 🦀 A RISC-V emulator written in Rust
Rust
8
star
40

react-elastic-modal

React elastic modal component.
JavaScript
7
star
41

youtube_music_game

yotube game sample
JavaScript
6
star
42

rxjs-lifegame

TypeScript
6
star
43

go-lifegame

Go
4
star
44

tomato_pasta

JavaScript
4
star
45

wu-diff-rs

Compute differences between two slices using wu(the O(NP)) algorithm.
Rust
4
star
46

react-draggable-custom

[deprecated]
JavaScript
4
star
47

armv4-emu-rs

🚧 [WIP] An ARMv4 emulator by Rust.
Rust
3
star
48

lcs-diff-rs

📃 Compute differences between two slices using LCS algorithm.
Rust
3
star
49

bounddoc

TypeScript
3
star
50

flava_cocos

cocos2d-JS music game
CoffeeScript
3
star
51

wasm-cv-with-laughing-man

😃 wasm + opencv + facedetect sample
JavaScript
3
star
52

wasi-threads-sandbox

WebAssembly
3
star
53

kanten_old

Rust
2
star
54

elixir_scraping_sample

Elixir
2
star
55

phoenix-redux-blog

WIP
Elixir
2
star
56

ng-resizable

TypeScript
1
star
57

kebab2camel

Transform camel case to kebab case
JavaScript
1
star
58

specterio

JavaScript
1
star
59

pixi-sandbox

pixi.js sandbox
JavaScript
1
star
60

use-resizable-table

TypeScript
1
star
61

c3

c3.jsを使用し、setTimerIntervalでチャートを描画するサンプル。
JavaScript
1
star
62

cv-wasm-face-detect-sample

JavaScript
1
star
63

raect-tutorial-with-redux-and-flowtype

JavaScript
1
star
64

node-go-with-browser

Dockerfile
1
star
65

wasip1-threads-rayon-example

JavaScript
1
star
66

rust-wasm-png-decoder-example

png decoder example by wasm32-unknown-unnkown.
JavaScript
1
star
67

planter

My plants
JavaScript
1
star
68

liquidfun_test

liquidfun_test
JavaScript
1
star
69

wasm-pixelmatch

JavaScript
1
star
70

react-sortable-column-sandbox

JavaScript
1
star
71

bmsjs-react

Browser BMS player project powered by React
JavaScript
1
star
72

chrome_serial_sample

chrome.serial API sample
CoffeeScript
1
star
73

cocos2d-JS_skeleton

cocos2d-JS v3.5+ skeleton
CoffeeScript
1
star
74

bms-gamepad-example

JavaScript
1
star
75

flava_sample

スマホブラウザで遊べる音ゲーサンプル
CoffeeScript
1
star
76

react-avaron-sample

React + Avaron sample
JavaScript
1
star
77

git-test

JavaScript
1
star
78

logue

1
star
79

cv-wasm

1
star