File: toc_simple.rs

package info (click to toggle)
rust-docx-rs 0.4.18-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,072 kB
  • sloc: xml: 194; makefile: 7
file content (29 lines) | stat: -rw-r--r-- 875 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use docx_rs::*;

pub fn main() -> Result<(), DocxError> {
    let path = std::path::Path::new("./output/toc_simple.docx");
    let file = std::fs::File::create(path).unwrap();
    let p1 = Paragraph::new()
        .add_run(Run::new().add_text("!!Hello"))
        .style("Heading1")
        .page_break_before(true);
    let style1 = Style::new("Heading1", StyleType::Paragraph).name("Heading 1");
    let p2 = Paragraph::new()
        .add_run(Run::new().add_text("World"))
        .style("Heading2")
        .page_break_before(true);

    Docx::new()
        .add_style(style1)
        .add_table_of_contents(
            TableOfContents::new()
                .heading_styles_range(1, 3)
                .alias("Table of contents")
                .auto(),
        )
        .add_paragraph(p1)
        .add_paragraph(p2)
        .build()
        .pack(file)?;
    Ok(())
}