Skip to main content

TableRow

Struct TableRow 

Source
pub struct TableRow {
    pub cells: Vec<TableCell>,
    pub repeat_as_header_row: bool,
    pub height_twips: Option<u32>,
    pub cant_split: bool,
}
Expand description

A table row: a sequence of cells.

Fields§

§cells: Vec<TableCell>

The cells that make up this row, in order.

§repeat_as_header_row: bool

Whether this row repeats as a header row on every page the table spans (w:trPr/w:tblHeader, CT_OnOff) — only meaningful, per ECMA-376, when set on one or more of the table’s topmost rows (Word stops honoring it on the first row where it isn’t set); not validated here, same “caller’s responsibility” convention as Paragraph.numbering_id referencing a declared list.

§height_twips: Option<u32>

This row’s height, in twips (w:trPr/w:trHeight/@w:val), or None to leave it unspecified (Word sizes the row to fit its content). Always written with w:hRule="atLeast" (ST_HeightRule’s other values, exact — which can clip content taller than the given height — and auto — equivalent to omitting the element entirely — aren’t modeled), meaning this is a minimum height Word may still exceed for taller content, never a hard cap.

§cant_split: bool

Whether this row is prevented from splitting across a page break (w:trPr/w:cantSplit, CT_OnOff) — when true, Word moves the whole row to the next page rather than breaking it mid-row.

Implementations§

Source§

impl TableRow

Source

pub fn new() -> TableRow

Creates an empty row.

Examples found in repository?
examples/docx_tables.rs (line 18)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("docx_tables.docx");
15
16    let plain_table = Table::new()
17        .with_row(
18            TableRow::new()
19                .with_cell(TableCell::with_text("Name"))
20                .with_cell(TableCell::with_text("Score")),
21        )
22        .with_row(
23            TableRow::new()
24                .with_cell(TableCell::with_text("Alice"))
25                .with_cell(TableCell::with_text("92")),
26        )
27        .with_row(
28            TableRow::new()
29                .with_cell(TableCell::with_text("Bob"))
30                .with_cell(TableCell::with_text("87")),
31        );
32
33    let merged_table = Table::new()
34        .with_row(
35            TableRow::new()
36                .with_repeat_as_header_row(true)
37                .with_cell(TableCell::with_text("Quarterly report").with_horizontal_span(3)),
38        )
39        .with_row(
40            TableRow::new()
41                .with_cell(
42                    TableCell::with_text("Region").with_vertical_merge(VerticalMerge::Restart),
43                )
44                .with_cell(TableCell::with_text("Q1"))
45                .with_cell(TableCell::with_text("Q2")),
46        )
47        .with_row(
48            TableRow::new()
49                .with_cell(TableCell::new().with_vertical_merge(VerticalMerge::Continue))
50                .with_cell(TableCell::with_text("1,200"))
51                .with_cell(TableCell::with_text("1,350")),
52        );
53
54    let styled_table = Table::new()
55        .with_column_widths(vec![3_000, 3_000, 3_000])
56        .with_border_color("2E74B5")
57        .with_indent_twips(360)
58        .with_row(
59            TableRow::new()
60                .with_height_twips(500)
61                .with_cell(TableCell::with_text("Header A").with_shading_color("D9E2F3"))
62                .with_cell(TableCell::with_text("Header B").with_shading_color("D9E2F3"))
63                .with_cell(TableCell::with_text("Header C").with_shading_color("D9E2F3")),
64        )
65        .with_row(
66            TableRow::new()
67                .with_cant_split(true)
68                .with_cell(TableCell::with_text("1").with_border(true))
69                .with_cell(TableCell::with_text("2").with_border(true))
70                .with_cell(TableCell::with_text("3").with_border(true)),
71        );
72
73    let document = Document::new()
74        .with_paragraph(heading("A plain table", false))
75        .with_table(plain_table)
76        .with_paragraph(heading(
77            "Merged cells: a spanning header row and a vertically merged column",
78            true,
79        ))
80        .with_table(merged_table)
81        .with_paragraph(heading(
82            "Column widths, border color, shading and indentation",
83            true,
84        ))
85        .with_table(styled_table);
86
87    document.save_to_file(&path)?;
88    println!("Wrote {}", path.display());
89    Ok(())
90}
Source

pub fn with_cell(self, cell: TableCell) -> TableRow

Appends a cell and returns the row for chaining.

Examples found in repository?
examples/docx_tables.rs (line 19)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("docx_tables.docx");
15
16    let plain_table = Table::new()
17        .with_row(
18            TableRow::new()
19                .with_cell(TableCell::with_text("Name"))
20                .with_cell(TableCell::with_text("Score")),
21        )
22        .with_row(
23            TableRow::new()
24                .with_cell(TableCell::with_text("Alice"))
25                .with_cell(TableCell::with_text("92")),
26        )
27        .with_row(
28            TableRow::new()
29                .with_cell(TableCell::with_text("Bob"))
30                .with_cell(TableCell::with_text("87")),
31        );
32
33    let merged_table = Table::new()
34        .with_row(
35            TableRow::new()
36                .with_repeat_as_header_row(true)
37                .with_cell(TableCell::with_text("Quarterly report").with_horizontal_span(3)),
38        )
39        .with_row(
40            TableRow::new()
41                .with_cell(
42                    TableCell::with_text("Region").with_vertical_merge(VerticalMerge::Restart),
43                )
44                .with_cell(TableCell::with_text("Q1"))
45                .with_cell(TableCell::with_text("Q2")),
46        )
47        .with_row(
48            TableRow::new()
49                .with_cell(TableCell::new().with_vertical_merge(VerticalMerge::Continue))
50                .with_cell(TableCell::with_text("1,200"))
51                .with_cell(TableCell::with_text("1,350")),
52        );
53
54    let styled_table = Table::new()
55        .with_column_widths(vec![3_000, 3_000, 3_000])
56        .with_border_color("2E74B5")
57        .with_indent_twips(360)
58        .with_row(
59            TableRow::new()
60                .with_height_twips(500)
61                .with_cell(TableCell::with_text("Header A").with_shading_color("D9E2F3"))
62                .with_cell(TableCell::with_text("Header B").with_shading_color("D9E2F3"))
63                .with_cell(TableCell::with_text("Header C").with_shading_color("D9E2F3")),
64        )
65        .with_row(
66            TableRow::new()
67                .with_cant_split(true)
68                .with_cell(TableCell::with_text("1").with_border(true))
69                .with_cell(TableCell::with_text("2").with_border(true))
70                .with_cell(TableCell::with_text("3").with_border(true)),
71        );
72
73    let document = Document::new()
74        .with_paragraph(heading("A plain table", false))
75        .with_table(plain_table)
76        .with_paragraph(heading(
77            "Merged cells: a spanning header row and a vertically merged column",
78            true,
79        ))
80        .with_table(merged_table)
81        .with_paragraph(heading(
82            "Column widths, border color, shading and indentation",
83            true,
84        ))
85        .with_table(styled_table);
86
87    document.save_to_file(&path)?;
88    println!("Wrote {}", path.display());
89    Ok(())
90}
Source

pub fn with_repeat_as_header_row(self, repeat_as_header_row: bool) -> TableRow

Marks this row as repeating as a header row on every page and returns it for chaining. See repeat_as_header_row’s doc comment.

Examples found in repository?
examples/docx_tables.rs (line 36)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("docx_tables.docx");
15
16    let plain_table = Table::new()
17        .with_row(
18            TableRow::new()
19                .with_cell(TableCell::with_text("Name"))
20                .with_cell(TableCell::with_text("Score")),
21        )
22        .with_row(
23            TableRow::new()
24                .with_cell(TableCell::with_text("Alice"))
25                .with_cell(TableCell::with_text("92")),
26        )
27        .with_row(
28            TableRow::new()
29                .with_cell(TableCell::with_text("Bob"))
30                .with_cell(TableCell::with_text("87")),
31        );
32
33    let merged_table = Table::new()
34        .with_row(
35            TableRow::new()
36                .with_repeat_as_header_row(true)
37                .with_cell(TableCell::with_text("Quarterly report").with_horizontal_span(3)),
38        )
39        .with_row(
40            TableRow::new()
41                .with_cell(
42                    TableCell::with_text("Region").with_vertical_merge(VerticalMerge::Restart),
43                )
44                .with_cell(TableCell::with_text("Q1"))
45                .with_cell(TableCell::with_text("Q2")),
46        )
47        .with_row(
48            TableRow::new()
49                .with_cell(TableCell::new().with_vertical_merge(VerticalMerge::Continue))
50                .with_cell(TableCell::with_text("1,200"))
51                .with_cell(TableCell::with_text("1,350")),
52        );
53
54    let styled_table = Table::new()
55        .with_column_widths(vec![3_000, 3_000, 3_000])
56        .with_border_color("2E74B5")
57        .with_indent_twips(360)
58        .with_row(
59            TableRow::new()
60                .with_height_twips(500)
61                .with_cell(TableCell::with_text("Header A").with_shading_color("D9E2F3"))
62                .with_cell(TableCell::with_text("Header B").with_shading_color("D9E2F3"))
63                .with_cell(TableCell::with_text("Header C").with_shading_color("D9E2F3")),
64        )
65        .with_row(
66            TableRow::new()
67                .with_cant_split(true)
68                .with_cell(TableCell::with_text("1").with_border(true))
69                .with_cell(TableCell::with_text("2").with_border(true))
70                .with_cell(TableCell::with_text("3").with_border(true)),
71        );
72
73    let document = Document::new()
74        .with_paragraph(heading("A plain table", false))
75        .with_table(plain_table)
76        .with_paragraph(heading(
77            "Merged cells: a spanning header row and a vertically merged column",
78            true,
79        ))
80        .with_table(merged_table)
81        .with_paragraph(heading(
82            "Column widths, border color, shading and indentation",
83            true,
84        ))
85        .with_table(styled_table);
86
87    document.save_to_file(&path)?;
88    println!("Wrote {}", path.display());
89    Ok(())
90}
Source

pub fn with_height_twips(self, height_twips: u32) -> TableRow

Sets this row’s height, in twips, and returns it for chaining. See height_twips’s doc comment.

Examples found in repository?
examples/docx_tables.rs (line 60)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("docx_tables.docx");
15
16    let plain_table = Table::new()
17        .with_row(
18            TableRow::new()
19                .with_cell(TableCell::with_text("Name"))
20                .with_cell(TableCell::with_text("Score")),
21        )
22        .with_row(
23            TableRow::new()
24                .with_cell(TableCell::with_text("Alice"))
25                .with_cell(TableCell::with_text("92")),
26        )
27        .with_row(
28            TableRow::new()
29                .with_cell(TableCell::with_text("Bob"))
30                .with_cell(TableCell::with_text("87")),
31        );
32
33    let merged_table = Table::new()
34        .with_row(
35            TableRow::new()
36                .with_repeat_as_header_row(true)
37                .with_cell(TableCell::with_text("Quarterly report").with_horizontal_span(3)),
38        )
39        .with_row(
40            TableRow::new()
41                .with_cell(
42                    TableCell::with_text("Region").with_vertical_merge(VerticalMerge::Restart),
43                )
44                .with_cell(TableCell::with_text("Q1"))
45                .with_cell(TableCell::with_text("Q2")),
46        )
47        .with_row(
48            TableRow::new()
49                .with_cell(TableCell::new().with_vertical_merge(VerticalMerge::Continue))
50                .with_cell(TableCell::with_text("1,200"))
51                .with_cell(TableCell::with_text("1,350")),
52        );
53
54    let styled_table = Table::new()
55        .with_column_widths(vec![3_000, 3_000, 3_000])
56        .with_border_color("2E74B5")
57        .with_indent_twips(360)
58        .with_row(
59            TableRow::new()
60                .with_height_twips(500)
61                .with_cell(TableCell::with_text("Header A").with_shading_color("D9E2F3"))
62                .with_cell(TableCell::with_text("Header B").with_shading_color("D9E2F3"))
63                .with_cell(TableCell::with_text("Header C").with_shading_color("D9E2F3")),
64        )
65        .with_row(
66            TableRow::new()
67                .with_cant_split(true)
68                .with_cell(TableCell::with_text("1").with_border(true))
69                .with_cell(TableCell::with_text("2").with_border(true))
70                .with_cell(TableCell::with_text("3").with_border(true)),
71        );
72
73    let document = Document::new()
74        .with_paragraph(heading("A plain table", false))
75        .with_table(plain_table)
76        .with_paragraph(heading(
77            "Merged cells: a spanning header row and a vertically merged column",
78            true,
79        ))
80        .with_table(merged_table)
81        .with_paragraph(heading(
82            "Column widths, border color, shading and indentation",
83            true,
84        ))
85        .with_table(styled_table);
86
87    document.save_to_file(&path)?;
88    println!("Wrote {}", path.display());
89    Ok(())
90}
Source

pub fn with_cant_split(self, cant_split: bool) -> TableRow

Marks this row as unable to split across a page break and returns it for chaining. See cant_split’s doc comment.

Examples found in repository?
examples/docx_tables.rs (line 67)
13fn main() -> office_toolkit::Result<()> {
14    let path = output_path("docx_tables.docx");
15
16    let plain_table = Table::new()
17        .with_row(
18            TableRow::new()
19                .with_cell(TableCell::with_text("Name"))
20                .with_cell(TableCell::with_text("Score")),
21        )
22        .with_row(
23            TableRow::new()
24                .with_cell(TableCell::with_text("Alice"))
25                .with_cell(TableCell::with_text("92")),
26        )
27        .with_row(
28            TableRow::new()
29                .with_cell(TableCell::with_text("Bob"))
30                .with_cell(TableCell::with_text("87")),
31        );
32
33    let merged_table = Table::new()
34        .with_row(
35            TableRow::new()
36                .with_repeat_as_header_row(true)
37                .with_cell(TableCell::with_text("Quarterly report").with_horizontal_span(3)),
38        )
39        .with_row(
40            TableRow::new()
41                .with_cell(
42                    TableCell::with_text("Region").with_vertical_merge(VerticalMerge::Restart),
43                )
44                .with_cell(TableCell::with_text("Q1"))
45                .with_cell(TableCell::with_text("Q2")),
46        )
47        .with_row(
48            TableRow::new()
49                .with_cell(TableCell::new().with_vertical_merge(VerticalMerge::Continue))
50                .with_cell(TableCell::with_text("1,200"))
51                .with_cell(TableCell::with_text("1,350")),
52        );
53
54    let styled_table = Table::new()
55        .with_column_widths(vec![3_000, 3_000, 3_000])
56        .with_border_color("2E74B5")
57        .with_indent_twips(360)
58        .with_row(
59            TableRow::new()
60                .with_height_twips(500)
61                .with_cell(TableCell::with_text("Header A").with_shading_color("D9E2F3"))
62                .with_cell(TableCell::with_text("Header B").with_shading_color("D9E2F3"))
63                .with_cell(TableCell::with_text("Header C").with_shading_color("D9E2F3")),
64        )
65        .with_row(
66            TableRow::new()
67                .with_cant_split(true)
68                .with_cell(TableCell::with_text("1").with_border(true))
69                .with_cell(TableCell::with_text("2").with_border(true))
70                .with_cell(TableCell::with_text("3").with_border(true)),
71        );
72
73    let document = Document::new()
74        .with_paragraph(heading("A plain table", false))
75        .with_table(plain_table)
76        .with_paragraph(heading(
77            "Merged cells: a spanning header row and a vertically merged column",
78            true,
79        ))
80        .with_table(merged_table)
81        .with_paragraph(heading(
82            "Column widths, border color, shading and indentation",
83            true,
84        ))
85        .with_table(styled_table);
86
87    document.save_to_file(&path)?;
88    println!("Wrote {}", path.display());
89    Ok(())
90}

Trait Implementations§

Source§

impl Clone for TableRow

Source§

fn clone(&self) -> TableRow

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 TableRow

Source§

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

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

impl Default for TableRow

Source§

fn default() -> TableRow

Returns the “default value” for a type. Read more
Source§

impl PartialEq for TableRow

Source§

fn eq(&self, other: &TableRow) -> 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 TableRow

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<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.