pub struct TableCell {
pub text_body: Option<TextBody>,
pub horizontal_span: Option<u32>,
pub vertical_span: Option<u32>,
pub horizontal_merge: bool,
pub vertical_merge: bool,
pub properties: Option<TableCellProperties>,
}Expand description
One cell of a TableRow (<a:tc>, CT_TableCell).
The merge fields are not grounded on a real fixture — see this module’s own top-level doc
comment; none of this project’s real table fixtures happens to exercise a merged cell, only the
base graphicFrame/tbl/tblGrid/tr/tc structure itself is fixture- confirmed. Built from
ECMA-376’s own CT_TableCell attribute list, which is genuinely different from
word_ooxml::TableCell’s merge model despite the conceptual overlap: WordprocessingML lets a
spanned cell be omitted from its row entirely (gridSpan absorbs the columns, no placeholder
w:tc needed for what it covers), but CT_TableCell has no such shortcut — every row must
carry exactly one <a:tc> per <a:gridCol>, and a merge is expressed by marking the absorbed
cells with hMerge/vMerge (plain booleans, not an enum) rather than omitting them, while the
top/left cell of the merge carries gridSpan/rowSpan (the count, not a boolean).
SlideTable’s writer enforces the “one cell per grid column, every row” shape by padding a
short row with empty cells rather than silently producing an invalid .pptx.
Fields§
§text_body: Option<TextBody>§horizontal_span: Option<u32>gridSpan — how many grid columns this cell spans (a horizontal merge, the top/left cell
only). None means 1 (no merge), matching CT_TableCell’s own schema default.
vertical_span: Option<u32>rowSpan — how many rows this cell spans (a vertical merge, the top/left cell only). None
means 1.
horizontal_merge: boolhMerge — true marks this cell as absorbed by a horizontal merge from the cell to its
left (this cell must still be present in the row, typically with no text of its own).
vertical_merge: boolvMerge — true marks this cell as absorbed by a vertical merge from the cell above it.
properties: Option<TableCellProperties><a:tcPr> (CT_TableCellProperties) — this cell’s own margins, vertical anchor, borders,
and background fill, overriding whatever the table’s style would otherwise apply. None
(the default) omits <a:tcPr> entirely — the cell simply inherits everything from the table
style, same “no override” default every other optional field in this crate uses.
Implementations§
Source§impl TableCell
impl TableCell
Sourcepub fn with_text_body(self, text_body: TextBody) -> TableCell
pub fn with_text_body(self, text_body: TextBody) -> TableCell
Sets this cell’s text content.
Sourcepub fn with_properties(self, properties: TableCellProperties) -> TableCell
pub fn with_properties(self, properties: TableCellProperties) -> TableCell
Sets this cell’s own margin/anchor/border/fill overrides (<a:tcPr>).
Sourcepub fn with_horizontal_span(self, span: u32) -> TableCell
pub fn with_horizontal_span(self, span: u32) -> TableCell
Marks this cell as the top/left cell of a horizontal merge spanning span grid columns —
the span - 1 cells to its right still need to be present in the row, each created via
TableCell::horizontally_merged.
Examples found in repository?
16fn main() -> office_toolkit::Result<()> {
17 let path = output_path("pptx_tables.pptx");
18
19 let plain_table = SlideTable::new(2, "Plain table", 5_000_000, 1_500_000)
20 .with_offset(838_200, 838_200)
21 .with_column_widths(vec![2_500_000, 2_500_000])
22 .with_row(
23 TableRow::new(500_000)
24 .with_cell(cell("Name"))
25 .with_cell(cell("Score")),
26 )
27 .with_row(
28 TableRow::new(500_000)
29 .with_cell(cell("Alice"))
30 .with_cell(cell("92")),
31 )
32 .with_row(
33 TableRow::new(500_000)
34 .with_cell(cell("Bob"))
35 .with_cell(cell("87")),
36 );
37
38 let merged_table = SlideTable::new(2, "Merged cells", 5_000_000, 1_000_000)
39 .with_offset(838_200, 838_200)
40 .with_column_widths(vec![1_667_000, 1_667_000, 1_666_000])
41 .with_row(
42 TableRow::new(500_000)
43 .with_cell(cell("Spanning header").with_horizontal_span(3))
44 .with_cell(TableCell::horizontally_merged())
45 .with_cell(TableCell::horizontally_merged()),
46 )
47 .with_row(
48 TableRow::new(500_000)
49 .with_cell(cell("A"))
50 .with_cell(cell("B"))
51 .with_cell(cell("C")),
52 );
53
54 let styled_table = SlideTable::new(2, "Styled table", 5_000_000, 1_500_000)
55 .with_offset(838_200, 838_200)
56 .with_style_id("{66BB4812-77A1-49B3-BDF9-0CCEB564D7B5}")
57 .with_style_first_row(true)
58 .with_style_band_rows(true)
59 .with_column_widths(vec![2_500_000, 2_500_000])
60 .with_row(
61 TableRow::new(500_000)
62 .with_cell(cell("Header A"))
63 .with_cell(cell("Header B")),
64 )
65 .with_row(
66 TableRow::new(500_000)
67 .with_cell(cell("1"))
68 .with_cell(cell("2")),
69 )
70 .with_row(
71 TableRow::new(500_000)
72 .with_cell(cell("3"))
73 .with_cell(cell("4")),
74 );
75
76 let presentation = Presentation::new()
77 .with_table_style(
78 SlideTableStyle::new(
79 "{66BB4812-77A1-49B3-BDF9-0CCEB564D7B5}",
80 "Custom Table Style",
81 )
82 .with_first_row(
83 TableStylePart::new()
84 .with_fill(Fill::Solid(Color::Rgb("2E74B5".to_string())))
85 .with_bold(true)
86 .with_text_color(Color::Rgb("FFFFFF".to_string())),
87 )
88 .with_band1_horizontal(
89 TableStylePart::new().with_fill(Fill::Solid(Color::Rgb("F2F2F2".to_string()))),
90 ),
91 )
92 .with_slide(Slide::new().with_shape(Shape::Table(plain_table)))
93 .with_slide(Slide::new().with_shape(Shape::Table(merged_table)))
94 .with_slide(Slide::new().with_shape(Shape::Table(styled_table)));
95
96 presentation.save_to_file(&path)?;
97 println!("Wrote {}", path.display());
98 Ok(())
99}Sourcepub fn with_vertical_span(self, span: u32) -> TableCell
pub fn with_vertical_span(self, span: u32) -> TableCell
Marks this cell as the top/left cell of a vertical merge spanning span rows — the span - 1 cells below it (same column, following rows) still need to be present, each created via
TableCell::vertically_merged.
Sourcepub fn horizontally_merged() -> TableCell
pub fn horizontally_merged() -> TableCell
An empty placeholder cell absorbed by a horizontal merge from its left neighbor
(hMerge="1").
Examples found in repository?
16fn main() -> office_toolkit::Result<()> {
17 let path = output_path("pptx_tables.pptx");
18
19 let plain_table = SlideTable::new(2, "Plain table", 5_000_000, 1_500_000)
20 .with_offset(838_200, 838_200)
21 .with_column_widths(vec![2_500_000, 2_500_000])
22 .with_row(
23 TableRow::new(500_000)
24 .with_cell(cell("Name"))
25 .with_cell(cell("Score")),
26 )
27 .with_row(
28 TableRow::new(500_000)
29 .with_cell(cell("Alice"))
30 .with_cell(cell("92")),
31 )
32 .with_row(
33 TableRow::new(500_000)
34 .with_cell(cell("Bob"))
35 .with_cell(cell("87")),
36 );
37
38 let merged_table = SlideTable::new(2, "Merged cells", 5_000_000, 1_000_000)
39 .with_offset(838_200, 838_200)
40 .with_column_widths(vec![1_667_000, 1_667_000, 1_666_000])
41 .with_row(
42 TableRow::new(500_000)
43 .with_cell(cell("Spanning header").with_horizontal_span(3))
44 .with_cell(TableCell::horizontally_merged())
45 .with_cell(TableCell::horizontally_merged()),
46 )
47 .with_row(
48 TableRow::new(500_000)
49 .with_cell(cell("A"))
50 .with_cell(cell("B"))
51 .with_cell(cell("C")),
52 );
53
54 let styled_table = SlideTable::new(2, "Styled table", 5_000_000, 1_500_000)
55 .with_offset(838_200, 838_200)
56 .with_style_id("{66BB4812-77A1-49B3-BDF9-0CCEB564D7B5}")
57 .with_style_first_row(true)
58 .with_style_band_rows(true)
59 .with_column_widths(vec![2_500_000, 2_500_000])
60 .with_row(
61 TableRow::new(500_000)
62 .with_cell(cell("Header A"))
63 .with_cell(cell("Header B")),
64 )
65 .with_row(
66 TableRow::new(500_000)
67 .with_cell(cell("1"))
68 .with_cell(cell("2")),
69 )
70 .with_row(
71 TableRow::new(500_000)
72 .with_cell(cell("3"))
73 .with_cell(cell("4")),
74 );
75
76 let presentation = Presentation::new()
77 .with_table_style(
78 SlideTableStyle::new(
79 "{66BB4812-77A1-49B3-BDF9-0CCEB564D7B5}",
80 "Custom Table Style",
81 )
82 .with_first_row(
83 TableStylePart::new()
84 .with_fill(Fill::Solid(Color::Rgb("2E74B5".to_string())))
85 .with_bold(true)
86 .with_text_color(Color::Rgb("FFFFFF".to_string())),
87 )
88 .with_band1_horizontal(
89 TableStylePart::new().with_fill(Fill::Solid(Color::Rgb("F2F2F2".to_string()))),
90 ),
91 )
92 .with_slide(Slide::new().with_shape(Shape::Table(plain_table)))
93 .with_slide(Slide::new().with_shape(Shape::Table(merged_table)))
94 .with_slide(Slide::new().with_shape(Shape::Table(styled_table)));
95
96 presentation.save_to_file(&path)?;
97 println!("Wrote {}", path.display());
98 Ok(())
99}Sourcepub fn vertically_merged() -> TableCell
pub fn vertically_merged() -> TableCell
An empty placeholder cell absorbed by a vertical merge from the cell above it
(vMerge="1").