Forked from: https://github.com/bokuweb/docx-rs
* Support for Line Spacing Signed-off-by: lkadalski <kadalski.lukasz@gmail.com> * Fixing clippy and yarn test Signed-off-by: lkadalski <kadalski.lukasz@gmail.com> |
||
---|---|---|
.github | ||
.vscode | ||
docs | ||
docx-core | ||
docx-wasm | ||
fixtures | ||
images | ||
output | ||
vrt | ||
.gitignore | ||
Cargo.lock | ||
Cargo.toml | ||
LICENSE | ||
README.md | ||
logo.png | ||
makefile | ||
renovate.json | ||
test.json |
README.md
A .docx file writer with Rust/WebAssembly.
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+