Skip to main content

NumberingDefinition

Struct NumberingDefinition 

Source
pub struct NumberingDefinition {
    pub id: u32,
    pub levels: Vec<ListLevel>,
}
Expand description

A numbering (list) definition declared in word/numbering.xml, referenced from paragraphs (Paragraph.numbering_id) by id.

WordprocessingML actually splits a list definition into two linked elements: w:abstractNum (the real level formatting, CT_AbstractNum) and w:num (CT_Num, a thin indirection paragraphs reference by numId, pointing at an abstractNumId) — this indirection exists so several w:num entries can share one w:abstractNum, which real Word documents do use, but which this crate doesn’t need for the common case of one standalone list. So this type collapses both into one value: id corresponds to w:num’s numId (what a paragraph actually references), and a dedicated w:abstractNum is always written alongside it internally — see writer.rs. Reading back a real, externally-authored document that DOES share one w:abstractNum across several w:num entries still works (each w:num becomes its own NumberingDefinition, with its levels resolved through whichever w:abstractNum it points to), just without preserving that sharing structure on a round trip.

Fields§

§id: u32

This definition’s id (w:num’s w:numId), referenced by Paragraph.numbering_id.

§levels: Vec<ListLevel>

The formatting for each indent level this list defines, in order (index 0 is the outermost level, w:lvl’s ilvl="0"). WordprocessingML allows up to 9 (ilvl 0-8); most real lists only need 1-3.

Implementations§

Source§

impl NumberingDefinition

Source

pub fn new(id: u32, levels: Vec<ListLevel>) -> NumberingDefinition

Creates a numbering definition with the given id and levels (fully custom — see NumberingDefinition::bullet/ NumberingDefinition::decimal for ready-made common cases).

Examples found in repository?
examples/docx_styles_and_lists.rs (lines 25-31)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("docx_styles_and_lists.docx");
15
16    let heading_style = Style::new("Heading1", "Heading 1", StyleKind::Paragraph)
17        .with_bold(true)
18        .with_font_size(32);
19    let emphasis_style = Style::new("StrongEmphasis", "Strong Emphasis", StyleKind::Character)
20        .with_bold(true)
21        .with_color("C00000");
22
23    let bulleted = NumberingDefinition::bullet(1);
24    let numbered = NumberingDefinition::decimal(2);
25    let custom = NumberingDefinition::new(
26        3,
27        vec![
28            ListLevel::new(NumberFormat::UpperRoman, "%1.", 720, 360),
29            ListLevel::new(NumberFormat::LowerLetter, "%2)", 1440, 360),
30        ],
31    );
32
33    let document = Document::new()
34        .with_style(heading_style)
35        .with_style(emphasis_style)
36        .with_numbering_definition(bulleted)
37        .with_numbering_definition(numbered)
38        .with_numbering_definition(custom)
39        .with_paragraph(heading("Named paragraph and character styles", false))
40        .with_paragraph(
41            Paragraph::with_text("This paragraph uses the Heading 1 style.")
42                .with_style_id("Heading1"),
43        )
44        .with_paragraph(
45            Paragraph::new()
46                .with_run(Run::new("Plain text, then "))
47                .with_run(Run::new("some strongly emphasized text").with_style_id("StrongEmphasis"))
48                .with_run(Run::new(", then plain text again.")),
49        )
50        .with_paragraph(heading("Bulleted list", true))
51        .with_paragraph(Paragraph::with_text("First item").with_numbering(1, 0))
52        .with_paragraph(Paragraph::with_text("Second item").with_numbering(1, 0))
53        .with_paragraph(Paragraph::with_text("A sub-item, one level deeper").with_numbering(1, 1))
54        .with_paragraph(heading("Numbered list", true))
55        .with_paragraph(Paragraph::with_text("First step").with_numbering(2, 0))
56        .with_paragraph(Paragraph::with_text("Second step").with_numbering(2, 0))
57        .with_paragraph(
58            Paragraph::with_text("A sub-step, cumulatively numbered").with_numbering(2, 1),
59        )
60        .with_paragraph(heading(
61            "Custom multi-level list (roman numerals, then letters)",
62            true,
63        ))
64        .with_paragraph(Paragraph::with_text("First top-level item").with_numbering(3, 0))
65        .with_paragraph(Paragraph::with_text("A lettered sub-item").with_numbering(3, 1))
66        .with_paragraph(Paragraph::with_text("Second top-level item").with_numbering(3, 0));
67
68    document.save_to_file(&path)?;
69    println!("Wrote {}", path.display());
70    Ok(())
71}
Source

pub fn bullet(id: u32) -> NumberingDefinition

A ready-made 3-level bulleted (unordered) list, using the same bullet characters, format and indentation Word’s own default “Bullets” gallery entry uses when it doesn’t need to fall back to a Wingdings/Symbol-font glyph — this crate doesn’t model fonts, so plain Unicode bullet characters are used instead of Word’s own Wingdings/Symbol ones (which would render as the wrong glyph without the matching font declared on the run).

Examples found in repository?
examples/docx_styles_and_lists.rs (line 23)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("docx_styles_and_lists.docx");
15
16    let heading_style = Style::new("Heading1", "Heading 1", StyleKind::Paragraph)
17        .with_bold(true)
18        .with_font_size(32);
19    let emphasis_style = Style::new("StrongEmphasis", "Strong Emphasis", StyleKind::Character)
20        .with_bold(true)
21        .with_color("C00000");
22
23    let bulleted = NumberingDefinition::bullet(1);
24    let numbered = NumberingDefinition::decimal(2);
25    let custom = NumberingDefinition::new(
26        3,
27        vec![
28            ListLevel::new(NumberFormat::UpperRoman, "%1.", 720, 360),
29            ListLevel::new(NumberFormat::LowerLetter, "%2)", 1440, 360),
30        ],
31    );
32
33    let document = Document::new()
34        .with_style(heading_style)
35        .with_style(emphasis_style)
36        .with_numbering_definition(bulleted)
37        .with_numbering_definition(numbered)
38        .with_numbering_definition(custom)
39        .with_paragraph(heading("Named paragraph and character styles", false))
40        .with_paragraph(
41            Paragraph::with_text("This paragraph uses the Heading 1 style.")
42                .with_style_id("Heading1"),
43        )
44        .with_paragraph(
45            Paragraph::new()
46                .with_run(Run::new("Plain text, then "))
47                .with_run(Run::new("some strongly emphasized text").with_style_id("StrongEmphasis"))
48                .with_run(Run::new(", then plain text again.")),
49        )
50        .with_paragraph(heading("Bulleted list", true))
51        .with_paragraph(Paragraph::with_text("First item").with_numbering(1, 0))
52        .with_paragraph(Paragraph::with_text("Second item").with_numbering(1, 0))
53        .with_paragraph(Paragraph::with_text("A sub-item, one level deeper").with_numbering(1, 1))
54        .with_paragraph(heading("Numbered list", true))
55        .with_paragraph(Paragraph::with_text("First step").with_numbering(2, 0))
56        .with_paragraph(Paragraph::with_text("Second step").with_numbering(2, 0))
57        .with_paragraph(
58            Paragraph::with_text("A sub-step, cumulatively numbered").with_numbering(2, 1),
59        )
60        .with_paragraph(heading(
61            "Custom multi-level list (roman numerals, then letters)",
62            true,
63        ))
64        .with_paragraph(Paragraph::with_text("First top-level item").with_numbering(3, 0))
65        .with_paragraph(Paragraph::with_text("A lettered sub-item").with_numbering(3, 1))
66        .with_paragraph(Paragraph::with_text("Second top-level item").with_numbering(3, 0));
67
68    document.save_to_file(&path)?;
69    println!("Wrote {}", path.display());
70    Ok(())
71}
Source

pub fn decimal(id: u32) -> NumberingDefinition

A ready-made 3-level numbered (ordered) list, using the same cumulative numbering (each level repeats its ancestors’ counters, e.g. “1.1.1.”) and indentation Word’s own default “Numbering” gallery entry uses.

Examples found in repository?
examples/docx_styles_and_lists.rs (line 24)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("docx_styles_and_lists.docx");
15
16    let heading_style = Style::new("Heading1", "Heading 1", StyleKind::Paragraph)
17        .with_bold(true)
18        .with_font_size(32);
19    let emphasis_style = Style::new("StrongEmphasis", "Strong Emphasis", StyleKind::Character)
20        .with_bold(true)
21        .with_color("C00000");
22
23    let bulleted = NumberingDefinition::bullet(1);
24    let numbered = NumberingDefinition::decimal(2);
25    let custom = NumberingDefinition::new(
26        3,
27        vec![
28            ListLevel::new(NumberFormat::UpperRoman, "%1.", 720, 360),
29            ListLevel::new(NumberFormat::LowerLetter, "%2)", 1440, 360),
30        ],
31    );
32
33    let document = Document::new()
34        .with_style(heading_style)
35        .with_style(emphasis_style)
36        .with_numbering_definition(bulleted)
37        .with_numbering_definition(numbered)
38        .with_numbering_definition(custom)
39        .with_paragraph(heading("Named paragraph and character styles", false))
40        .with_paragraph(
41            Paragraph::with_text("This paragraph uses the Heading 1 style.")
42                .with_style_id("Heading1"),
43        )
44        .with_paragraph(
45            Paragraph::new()
46                .with_run(Run::new("Plain text, then "))
47                .with_run(Run::new("some strongly emphasized text").with_style_id("StrongEmphasis"))
48                .with_run(Run::new(", then plain text again.")),
49        )
50        .with_paragraph(heading("Bulleted list", true))
51        .with_paragraph(Paragraph::with_text("First item").with_numbering(1, 0))
52        .with_paragraph(Paragraph::with_text("Second item").with_numbering(1, 0))
53        .with_paragraph(Paragraph::with_text("A sub-item, one level deeper").with_numbering(1, 1))
54        .with_paragraph(heading("Numbered list", true))
55        .with_paragraph(Paragraph::with_text("First step").with_numbering(2, 0))
56        .with_paragraph(Paragraph::with_text("Second step").with_numbering(2, 0))
57        .with_paragraph(
58            Paragraph::with_text("A sub-step, cumulatively numbered").with_numbering(2, 1),
59        )
60        .with_paragraph(heading(
61            "Custom multi-level list (roman numerals, then letters)",
62            true,
63        ))
64        .with_paragraph(Paragraph::with_text("First top-level item").with_numbering(3, 0))
65        .with_paragraph(Paragraph::with_text("A lettered sub-item").with_numbering(3, 1))
66        .with_paragraph(Paragraph::with_text("Second top-level item").with_numbering(3, 0));
67
68    document.save_to_file(&path)?;
69    println!("Wrote {}", path.display());
70    Ok(())
71}

Trait Implementations§

Source§

impl Clone for NumberingDefinition

Source§

fn clone(&self) -> NumberingDefinition

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NumberingDefinition

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for NumberingDefinition

Source§

impl PartialEq for NumberingDefinition

Source§

fn eq(&self, other: &NumberingDefinition) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for NumberingDefinition

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.