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: boolWhether 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: boolWhether 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
impl TableRow
Sourcepub fn new() -> TableRow
pub fn new() -> TableRow
Creates an empty row.
Examples found in repository?
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}Sourcepub fn with_cell(self, cell: TableCell) -> TableRow
pub fn with_cell(self, cell: TableCell) -> TableRow
Appends a cell and returns the row for chaining.
Examples found in repository?
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}Sourcepub fn with_repeat_as_header_row(self, repeat_as_header_row: bool) -> TableRow
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?
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}Sourcepub fn with_height_twips(self, height_twips: u32) -> TableRow
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?
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}Sourcepub fn with_cant_split(self, cant_split: bool) -> TableRow
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?
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}