chore: Add examples (#26)
parent
22aee045a0
commit
c80be45824
34
README.md
34
README.md
|
@ -10,11 +10,11 @@
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
``` rust
|
```rust
|
||||||
use docx_core::*;
|
use docx_core::*;
|
||||||
|
|
||||||
pub fn hello() -> Result<(), DocxError> {
|
pub fn hello() -> Result<(), DocxError> {
|
||||||
let path = std::path::Path::new("./tests/output/hello.docx");
|
let path = std::path::Path::new("./hello.docx");
|
||||||
let file = std::fs::File::create(&path).unwrap();
|
let file = std::fs::File::create(&path).unwrap();
|
||||||
Docx::new()
|
Docx::new()
|
||||||
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
|
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
|
||||||
|
@ -26,8 +26,36 @@ pub fn hello() -> Result<(), DocxError> {
|
||||||
|
|
||||||
### More examples
|
### More examples
|
||||||
|
|
||||||
* [Indent](https://github.com/bokuweb/docx-rs/blob/master/docx-core/examples/indent.rs)
|
- [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)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- [x] Paragraph
|
- [x] Paragraph
|
||||||
|
- [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
|
||||||
|
- [x]
|
||||||
|
- [ ] Image
|
||||||
|
- [x] Style
|
||||||
|
- [x] Table
|
||||||
|
- [x] HIstory
|
||||||
|
- [ ] Table of contents
|
||||||
|
- [ ] Section
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
use docx_core::*;
|
||||||
|
|
||||||
|
pub fn main() -> Result<(), DocxError> {
|
||||||
|
let path = std::path::Path::new("./alignment.docx");
|
||||||
|
let file = std::fs::File::create(&path).unwrap();
|
||||||
|
Docx::new()
|
||||||
|
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
|
||||||
|
.add_paragraph(
|
||||||
|
Paragraph::new()
|
||||||
|
.add_run(Run::new().add_text(" World"))
|
||||||
|
.align(AlignmentType::Right),
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
.pack(file)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
use docx_core::*;
|
||||||
|
|
||||||
|
pub fn main() -> Result<(), DocxError> {
|
||||||
|
let path = std::path::Path::new("./comment.docx");
|
||||||
|
let file = std::fs::File::create(&path).unwrap();
|
||||||
|
Docx::new()
|
||||||
|
.add_paragraph(
|
||||||
|
Paragraph::new()
|
||||||
|
.add_comment_start(
|
||||||
|
Comment::new(1)
|
||||||
|
.author("bokuweb")
|
||||||
|
.date("2019-01-01T00:00:00Z")
|
||||||
|
.paragraph(Paragraph::new().add_run(Run::new().add_text("Hello"))),
|
||||||
|
)
|
||||||
|
.add_comment_end(1),
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
.pack(file)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
use docx_core::*;
|
||||||
|
|
||||||
|
pub fn main() -> Result<(), DocxError> {
|
||||||
|
let path = std::path::Path::new("./output/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(())
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
use docx_core::*;
|
||||||
|
|
||||||
|
pub fn main() -> Result<(), DocxError> {
|
||||||
|
let path = std::path::Path::new("./history.docx");
|
||||||
|
let file = std::fs::File::create(&path).unwrap();
|
||||||
|
Docx::new()
|
||||||
|
.add_paragraph(
|
||||||
|
Paragraph::new()
|
||||||
|
.add_insert(
|
||||||
|
Insert::new(Run::new().add_text("Hello"))
|
||||||
|
.author("bokuweb")
|
||||||
|
.date("2019-01-01T00:00:00Z"),
|
||||||
|
)
|
||||||
|
.add_delete(Delete::new(Run::new().add_delete_text("World"))),
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
.pack(file)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -3,27 +3,27 @@ use docx_core::*;
|
||||||
pub const DUMMY: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
|
pub const DUMMY: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
|
||||||
|
|
||||||
pub fn main() -> Result<(), DocxError> {
|
pub fn main() -> Result<(), DocxError> {
|
||||||
let path = std::path::Path::new("./output/indent.docx");
|
let path = std::path::Path::new("./output/indent.docx");
|
||||||
let file = std::fs::File::create(&path).unwrap();
|
let file = std::fs::File::create(&path).unwrap();
|
||||||
Docx::new()
|
Docx::new()
|
||||||
.add_paragraph(
|
.add_paragraph(
|
||||||
Paragraph::new()
|
Paragraph::new()
|
||||||
.add_run(Run::new().add_text(DUMMY))
|
.add_run(Run::new().add_text(DUMMY))
|
||||||
.indent(840, None),
|
.indent(840, None),
|
||||||
)
|
)
|
||||||
.add_paragraph(Paragraph::new())
|
.add_paragraph(Paragraph::new())
|
||||||
.add_paragraph(
|
.add_paragraph(
|
||||||
Paragraph::new()
|
Paragraph::new()
|
||||||
.add_run(Run::new().add_text(DUMMY))
|
.add_run(Run::new().add_text(DUMMY))
|
||||||
.indent(840, Some(SpecialIndentType::FirstLine(720))),
|
.indent(840, Some(SpecialIndentType::FirstLine(720))),
|
||||||
)
|
)
|
||||||
.add_paragraph(Paragraph::new())
|
.add_paragraph(Paragraph::new())
|
||||||
.add_paragraph(
|
.add_paragraph(
|
||||||
Paragraph::new()
|
Paragraph::new()
|
||||||
.add_run(Run::new().add_text(DUMMY))
|
.add_run(Run::new().add_text(DUMMY))
|
||||||
.indent(1560, Some(SpecialIndentType::Hanging(720))),
|
.indent(1560, Some(SpecialIndentType::Hanging(720))),
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
.pack(file)?;
|
.pack(file)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
use docx_core::*;
|
||||||
|
|
||||||
|
pub fn main() -> Result<(), DocxError> {
|
||||||
|
let path = std::path::Path::new("./numbering.docx");
|
||||||
|
let file = std::fs::File::create(&path).unwrap();
|
||||||
|
Docx::new()
|
||||||
|
.add_paragraph(
|
||||||
|
Paragraph::new()
|
||||||
|
.add_run(Run::new().add_text("Hello"))
|
||||||
|
.numbering(NumberingId::new(2), IndentLevel::new(0)),
|
||||||
|
)
|
||||||
|
.add_numbering(
|
||||||
|
Numbering::new(2).add_level(
|
||||||
|
Level::new(
|
||||||
|
0,
|
||||||
|
Start::new(1),
|
||||||
|
NumberFormat::new("decimal"),
|
||||||
|
LevelText::new("Section %1."),
|
||||||
|
LevelJc::new("left"),
|
||||||
|
)
|
||||||
|
.indent(1620, Some(SpecialIndentType::Hanging(320))),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
.pack(file)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
use docx_core::*;
|
||||||
|
|
||||||
|
pub fn main() -> Result<(), DocxError> {
|
||||||
|
let path = std::path::Path::new("./table.docx");
|
||||||
|
let file = std::fs::File::create(&path).unwrap();
|
||||||
|
|
||||||
|
let table = Table::new(vec![
|
||||||
|
TableRow::new(vec![
|
||||||
|
TableCell::new()
|
||||||
|
.add_paragraph(Paragraph::new())
|
||||||
|
.grid_span(2),
|
||||||
|
TableCell::new()
|
||||||
|
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
|
||||||
|
.vertical_merge(VMergeType::Restart),
|
||||||
|
]),
|
||||||
|
TableRow::new(vec![
|
||||||
|
TableCell::new()
|
||||||
|
.add_paragraph(Paragraph::new())
|
||||||
|
.vertical_merge(VMergeType::Restart),
|
||||||
|
TableCell::new().add_paragraph(Paragraph::new()),
|
||||||
|
TableCell::new()
|
||||||
|
.add_paragraph(Paragraph::new())
|
||||||
|
.vertical_merge(VMergeType::Continue),
|
||||||
|
]),
|
||||||
|
TableRow::new(vec![
|
||||||
|
TableCell::new()
|
||||||
|
.add_paragraph(Paragraph::new())
|
||||||
|
.vertical_merge(VMergeType::Continue),
|
||||||
|
TableCell::new().add_paragraph(Paragraph::new()),
|
||||||
|
TableCell::new()
|
||||||
|
.add_paragraph(Paragraph::new())
|
||||||
|
.vertical_merge(VMergeType::Continue),
|
||||||
|
]),
|
||||||
|
])
|
||||||
|
.set_grid(vec![2000, 2000, 2000]);
|
||||||
|
Docx::new().add_table(table).build().pack(file)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -223,7 +223,11 @@ pub fn history() -> Result<(), DocxError> {
|
||||||
Docx::new()
|
Docx::new()
|
||||||
.add_paragraph(
|
.add_paragraph(
|
||||||
Paragraph::new()
|
Paragraph::new()
|
||||||
.add_insert(Insert::new(Run::new().add_text("Hello")))
|
.add_insert(
|
||||||
|
Insert::new(Run::new().add_text("Hello"))
|
||||||
|
.author("bokuweb")
|
||||||
|
.date("2019-01-01T00:00:00Z"),
|
||||||
|
)
|
||||||
.add_delete(Delete::new(Run::new().add_delete_text("World"))),
|
.add_delete(Delete::new(Run::new().add_delete_text("World"))),
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
|
|
Loading…
Reference in New Issue