docx-rs/README.md

109 lines
2.5 KiB
Markdown
Raw Normal View History

2020-01-17 16:07:44 +02:00
<p align="center"><img src ="https://github.com/bokuweb/docx-rs/blob/master/logo.png?raw=true" /></p>
<p align="center">
2020-02-11 15:15:44 +02:00
A .docx file reader/writer with Rust/WebAssembly.
2020-01-17 16:07:44 +02:00
</p>
---
2019-11-12 06:45:04 +02:00
[![GitHub Actions Status](https://github.com/bokuweb/docx-rs/workflows/Continuous%20Integration/badge.svg)](https://github.com/bokuweb/docx-rs/actions)
2020-02-14 03:37:46 +02:00
[![docx-rs at crates.io](https://img.shields.io/crates/v/docx-rs.svg)](https://crates.io/crates/docx-rs)
[![](https://img.shields.io/npm/v/docx-wasm.svg)](https://www.npmjs.com/package/docx-wasm)
2019-11-15 11:15:43 +02:00
2020-01-24 12:46:01 +02:00
## Installation
### Rust
```
[dependencies]
docx-rs = "0.2.0"
```
### Browser/Node.js
```
yarn add docx-wasm
```
2020-01-17 17:19:07 +02:00
## Example
### Rust
2020-01-24 11:50:16 +02:00
```rust
use docx_rs::*;
2020-01-17 17:19:07 +02:00
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(())
2020-01-17 17:19:07 +02:00
}
```
### Browser
```javascript
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 buf = new w.Docx()
.addParagraph(
new w.Paragraph().addRun(new w.Run().addText("Hello world!!"))
)
.build();
saveAs(new Blob([buf]), "hello.docx");
});
```
### Node.js
```javascript
const w = require("docx-wasm");
const { writeFileSync } = require("fs");
const buf = new w.Docx()
.addParagraph(new w.Paragraph().addRun(new w.Run().addText("Hello world!!")))
.build();
writeFileSync("hello.docx", buf);
```
2020-01-17 17:20:46 +02:00
### More examples
2020-01-24 11:50:16 +02:00
- [Minimum](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/hello.rs)
- [Indent](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/indent.rs)
- [Alignment](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/alignment.rs)
- [Numbering](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/numbering.rs)
- [Table](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/table.rs)
- [Comment](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/comment.rs)
- [History](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/history.rs)
2020-01-17 17:20:46 +02:00
2020-01-17 17:19:07 +02:00
## Features
2019-11-15 11:15:43 +02:00
- [x] Paragraph
2020-01-24 11:50:16 +02:00
- [x] Alignment
- [x] Indent
- [x] Numbering
- [x] Run
- [x] Bold
- [x] Size
- [x] Color
- [x] Highlight
- [x] Underline
- [x] vanish
- [x] Italic
- [x] Break
- [ ] Header
- [ ] Footer
- [x] Comment
- [ ] Image
- [x] Style
- [x] Table
- [x] HIstory
- [ ] Table of contents
- [ ] Section