Skip to main content

Table

Struct Table 

Source
pub struct Table {
    pub rows: Vec<TableRow>,
    pub column_widths: Vec<u32>,
    pub x: u32,
    pub y: u32,
}
Expand description

Table definition with rows and positioning

Fields§

§rows: Vec<TableRow>

Table rows

§column_widths: Vec<u32>

Column widths in EMU

§x: u32

X position in EMU

§y: u32

Y position in EMU

Implementations§

Source§

impl Table

Source

pub fn new(rows: Vec<TableRow>, column_widths: Vec<u32>, x: u32, y: u32) -> Self

Create a new table with explicit rows, column widths, and position

Examples found in repository?
examples/table_demo.rs (lines 65-70)
29fn create_employee_table() -> Table {
30    let header_cells = vec![
31        TableCell::new("Name").bold().background_color("4F81BD"),
32        TableCell::new("Department").bold().background_color("4F81BD"),
33        TableCell::new("Status").bold().background_color("4F81BD"),
34    ];
35    let header_row = TableRow::new(header_cells);
36
37    let rows = vec![
38        TableRow::new(vec![
39            TableCell::new("Alice Johnson"),
40            TableCell::new("Engineering"),
41            TableCell::new("Active"),
42        ]),
43        TableRow::new(vec![
44            TableCell::new("Bob Smith"),
45            TableCell::new("Sales"),
46            TableCell::new("Active"),
47        ]),
48        TableRow::new(vec![
49            TableCell::new("Carol Davis"),
50            TableCell::new("Marketing"),
51            TableCell::new("On Leave"),
52        ]),
53        TableRow::new(vec![
54            TableCell::new("David Wilson"),
55            TableCell::new("Engineering"),
56            TableCell::new("Active"),
57        ]),
58        TableRow::new(vec![
59            TableCell::new("Emma Brown"),
60            TableCell::new("HR"),
61            TableCell::new("Active"),
62        ]),
63    ];
64
65    Table::new(
66        vec![vec![header_row], rows].concat(),
67        vec![2000000, 2500000, 1500000],
68        500000,
69        1500000,
70    )
71}
72
73fn create_sales_table() -> Table {
74    let header_cells = vec![
75        TableCell::new("Product").bold().background_color("003366"),
76        TableCell::new("Revenue").bold().background_color("003366"),
77        TableCell::new("Growth").bold().background_color("003366"),
78    ];
79    let header_row = TableRow::new(header_cells);
80
81    let rows = vec![
82        TableRow::new(vec![
83            TableCell::new("Cloud Services"),
84            TableCell::new("$450K"),
85            TableCell::new("+28%"),
86        ]),
87        TableRow::new(vec![
88            TableCell::new("Enterprise Suite"),
89            TableCell::new("$320K"),
90            TableCell::new("+15%"),
91        ]),
92        TableRow::new(vec![
93            TableCell::new("Developer Tools"),
94            TableCell::new("$280K"),
95            TableCell::new("+42%"),
96        ]),
97        TableRow::new(vec![
98            TableCell::new("Mobile App"),
99            TableCell::new("$195K"),
100            TableCell::new("+35%"),
101        ]),
102        TableRow::new(vec![
103            TableCell::new("Support Services"),
104            TableCell::new("$155K"),
105            TableCell::new("+12%"),
106        ]),
107    ];
108
109    Table::new(
110        vec![vec![header_row], rows].concat(),
111        vec![2200000, 2000000, 1800000],
112        500000,
113        1500000,
114    )
115}
116
117fn create_quarterly_table() -> Table {
118    let header_cells = vec![
119        TableCell::new("Quarter").bold().background_color("1F497D"),
120        TableCell::new("Revenue").bold().background_color("1F497D"),
121        TableCell::new("Profit").bold().background_color("1F497D"),
122    ];
123    let header_row = TableRow::new(header_cells);
124
125    let q1_cells = vec![
126        TableCell::new("Q1 2025"),
127        TableCell::new("$450K"),
128        TableCell::new("$90K"),
129    ];
130    let q1 = TableRow::new(q1_cells);
131
132    let q2_cells = vec![
133        TableCell::new("Q2 2025"),
134        TableCell::new("$520K"),
135        TableCell::new("$110K"),
136    ];
137    let q2 = TableRow::new(q2_cells);
138
139    let q3_cells = vec![
140        TableCell::new("Q3 2025"),
141        TableCell::new("$580K"),
142        TableCell::new("$130K"),
143    ];
144    let q3 = TableRow::new(q3_cells);
145
146    Table::new(
147        vec![header_row, q1, q2, q3],
148        vec![2000000, 2000000, 2000000],
149        500000,
150        1500000,
151    )
152}
More examples
Hide additional examples
examples/table_generation.rs (lines 107-112)
81fn create_styled_table_example() -> Result<(), Box<dyn std::error::Error>> {
82    let header_cells = vec![
83        TableCell::new("Name").bold().background_color("003366"),
84        TableCell::new("Age").bold().background_color("003366"),
85        TableCell::new("City").bold().background_color("003366"),
86    ];
87    let header_row = TableRow::new(header_cells);
88
89    let data_rows = vec![
90        TableRow::new(vec![
91            TableCell::new("Alice"),
92            TableCell::new("30"),
93            TableCell::new("NYC"),
94        ]),
95        TableRow::new(vec![
96            TableCell::new("Bob"),
97            TableCell::new("28"),
98            TableCell::new("LA"),
99        ]),
100        TableRow::new(vec![
101            TableCell::new("Carol"),
102            TableCell::new("35"),
103            TableCell::new("Chicago"),
104        ]),
105    ];
106
107    let table = Table::new(
108        vec![vec![header_row], data_rows].concat(),
109        vec![1500000, 1500000, 1500000],
110        500000,
111        1500000,
112    );
113
114    let slides = vec![
115        SlideContent::new("Styled Table")
116            .title_bold(true)
117            .title_color("003366")
118            .add_bullet("Table with formatting"),
119        SlideContent::new("People Data")
120            .table(table),
121    ];
122
123    let pptx_data = create_pptx_with_content("Styled Table", slides)?;
124    fs::write("examples/output/styled_table.pptx", pptx_data)?;
125    Ok(())
126}
127
128fn create_data_table_example() -> Result<(), Box<dyn std::error::Error>> {
129    let header_cells = vec![
130        TableCell::new("Product").bold().background_color("1F497D"),
131        TableCell::new("Revenue").bold().background_color("1F497D"),
132        TableCell::new("Growth").bold().background_color("1F497D"),
133    ];
134    let header_row = TableRow::new(header_cells);
135
136    let data_rows = vec![
137        TableRow::new(vec![
138            TableCell::new("Product A"),
139            TableCell::new("$100K"),
140            TableCell::new("+15%"),
141        ]),
142        TableRow::new(vec![
143            TableCell::new("Product B"),
144            TableCell::new("$150K"),
145            TableCell::new("+22%"),
146        ]),
147        TableRow::new(vec![
148            TableCell::new("Product C"),
149            TableCell::new("$200K"),
150            TableCell::new("+18%"),
151        ]),
152    ];
153
154    let table = Table::new(
155        vec![vec![header_row], data_rows].concat(),
156        vec![2000000, 2000000, 1500000],
157        457200,
158        1400000,
159    );
160
161    let slides = vec![
162        SlideContent::new("Sales Data Table")
163            .title_bold(true)
164            .title_size(48)
165            .add_bullet("Quarterly sales figures"),
166        SlideContent::new("Q1 2025 Sales")
167            .table(table),
168        SlideContent::new("Summary")
169            .content_bold(true)
170            .add_bullet("Total Revenue: $450K")
171            .add_bullet("Average Growth: +18.3%")
172            .add_bullet("Best Performer: Product C"),
173    ];
174
175    let pptx_data = create_pptx_with_content("Sales Data", slides)?;
176    fs::write("examples/output/data_table.pptx", pptx_data)?;
177    Ok(())
178}
179
180fn create_multiple_tables_example() -> Result<(), Box<dyn std::error::Error>> {
181    // Table 1: Employees
182    let emp_header = TableRow::new(vec![
183        TableCell::new("ID").bold().background_color("4F81BD"),
184        TableCell::new("Name").bold().background_color("4F81BD"),
185        TableCell::new("Department").bold().background_color("4F81BD"),
186    ]);
187    let emp_rows = vec![
188        TableRow::new(vec![
189            TableCell::new("001"),
190            TableCell::new("Alice"),
191            TableCell::new("Engineering"),
192        ]),
193        TableRow::new(vec![
194            TableCell::new("002"),
195            TableCell::new("Bob"),
196            TableCell::new("Sales"),
197        ]),
198        TableRow::new(vec![
199            TableCell::new("003"),
200            TableCell::new("Carol"),
201            TableCell::new("Marketing"),
202        ]),
203    ];
204    let emp_table = Table::new(
205        vec![vec![emp_header], emp_rows].concat(),
206        vec![1000000, 2000000, 2000000],
207        500000,
208        1500000,
209    );
210
211    // Table 2: Projects
212    let proj_header = TableRow::new(vec![
213        TableCell::new("Project").bold().background_color("003366"),
214        TableCell::new("Status").bold().background_color("003366"),
215        TableCell::new("Owner").bold().background_color("003366"),
216    ]);
217    let proj_rows = vec![
218        TableRow::new(vec![
219            TableCell::new("Project A"),
220            TableCell::new("In Progress"),
221            TableCell::new("Alice"),
222        ]),
223        TableRow::new(vec![
224            TableCell::new("Project B"),
225            TableCell::new("Completed"),
226            TableCell::new("Bob"),
227        ]),
228        TableRow::new(vec![
229            TableCell::new("Project C"),
230            TableCell::new("Planning"),
231            TableCell::new("Carol"),
232        ]),
233    ];
234    let proj_table = Table::new(
235        vec![vec![proj_header], proj_rows].concat(),
236        vec![2000000, 2000000, 1500000],
237        500000,
238        1500000,
239    );
240
241    let slides = vec![
242        SlideContent::new("Multiple Tables")
243            .title_bold(true)
244            .add_bullet("Slide with multiple tables"),
245        SlideContent::new("Table 1: Employees")
246            .table(emp_table),
247        SlideContent::new("Table 2: Projects")
248            .table(proj_table),
249        SlideContent::new("Summary")
250            .add_bullet("Total Employees: 3")
251            .add_bullet("Active Projects: 3")
252            .add_bullet("Completion Rate: 33%"),
253    ];
254
255    let pptx_data = create_pptx_with_content("Multiple Tables", slides)?;
256    fs::write("examples/output/multiple_tables.pptx", pptx_data)?;
257    Ok(())
258}
259
260/// Helper function to demonstrate table creation
261#[allow(dead_code)]
262fn create_table_structure() -> Table {
263    // Create table using builder
264    TableBuilder::new(vec![1000000, 1000000, 1000000])
265        .position(500000, 1000000)
266        .add_simple_row(vec!["Header 1", "Header 2", "Header 3"])
267        .add_simple_row(vec!["Data 1", "Data 2", "Data 3"])
268        .add_simple_row(vec!["Data 4", "Data 5", "Data 6"])
269        .build()
270}
271
272/// Helper function to demonstrate styled table
273#[allow(dead_code)]
274fn create_styled_table() -> Table {
275    let header_cells = vec![
276        TableCell::new("Name").bold().background_color("003366"),
277        TableCell::new("Age").bold().background_color("003366"),
278        TableCell::new("City").bold().background_color("003366"),
279    ];
280    let header_row = TableRow::new(header_cells);
281
282    let data_cells = vec![
283        TableCell::new("Alice"),
284        TableCell::new("30"),
285        TableCell::new("NYC"),
286    ];
287    let data_row = TableRow::new(data_cells);
288
289    Table::new(
290        vec![header_row, data_row],
291        vec![1000000, 1000000, 1000000],
292        500000,
293        1000000,
294    )
295}
examples/table_text_formatting.rs (lines 69-74)
33fn create_text_formatting_table() -> Table {
34    let header_cells = vec![
35        TableCell::new("Style").bold().background_color("4F81BD"),
36        TableCell::new("Example").bold().background_color("4F81BD"),
37        TableCell::new("Description").bold().background_color("4F81BD"),
38    ];
39    let header_row = TableRow::new(header_cells);
40
41    let rows = vec![
42        TableRow::new(vec![
43            TableCell::new("Bold"),
44            TableCell::new("Bold Text").bold(),
45            TableCell::new("Text with bold formatting"),
46        ]),
47        TableRow::new(vec![
48            TableCell::new("Italic"),
49            TableCell::new("Italic Text").italic(),
50            TableCell::new("Text with italic formatting"),
51        ]),
52        TableRow::new(vec![
53            TableCell::new("Underline"),
54            TableCell::new("Underlined Text").underline(),
55            TableCell::new("Text with underline formatting"),
56        ]),
57        TableRow::new(vec![
58            TableCell::new("Bold + Italic"),
59            TableCell::new("Bold Italic Text").bold().italic(),
60            TableCell::new("Text with both bold and italic"),
61        ]),
62        TableRow::new(vec![
63            TableCell::new("All Three"),
64            TableCell::new("Bold Italic Underlined").bold().italic().underline(),
65            TableCell::new("Text with all formatting options"),
66        ]),
67    ];
68
69    Table::new(
70        vec![vec![header_row], rows].concat(),
71        vec![2000000, 3000000, 3000000],
72        500000,
73        1500000,
74    )
75}
76
77fn create_color_table() -> Table {
78    let header_cells = vec![
79        TableCell::new("Text Color").bold().background_color("1F497D"),
80        TableCell::new("Background").bold().background_color("1F497D"),
81        TableCell::new("Example").bold().background_color("1F497D"),
82    ];
83    let header_row = TableRow::new(header_cells);
84
85    let rows = vec![
86        TableRow::new(vec![
87            TableCell::new("Red"),
88            TableCell::new("White"),
89            TableCell::new("Red Text").text_color("FF0000").background_color("FFFFFF"),
90        ]),
91        TableRow::new(vec![
92            TableCell::new("Blue"),
93            TableCell::new("Yellow"),
94            TableCell::new("Blue Text").text_color("0000FF").background_color("FFFF00"),
95        ]),
96        TableRow::new(vec![
97            TableCell::new("Green"),
98            TableCell::new("Light Gray"),
99            TableCell::new("Green Text").text_color("00FF00").background_color("E0E0E0"),
100        ]),
101        TableRow::new(vec![
102            TableCell::new("Purple"),
103            TableCell::new("White"),
104            TableCell::new("Purple Text").text_color("800080").background_color("FFFFFF"),
105        ]),
106    ];
107
108    Table::new(
109        vec![vec![header_row], rows].concat(),
110        vec![2000000, 2000000, 4000000],
111        500000,
112        1500000,
113    )
114}
115
116fn create_font_table() -> Table {
117    let header_cells = vec![
118        TableCell::new("Font Size").bold().background_color("366092"),
119        TableCell::new("Font Family").bold().background_color("366092"),
120        TableCell::new("Example").bold().background_color("366092"),
121    ];
122    let header_row = TableRow::new(header_cells);
123
124    let rows = vec![
125        TableRow::new(vec![
126            TableCell::new("12pt"),
127            TableCell::new("Arial"),
128            TableCell::new("Small Arial Text").font_size(12).font_family("Arial"),
129        ]),
130        TableRow::new(vec![
131            TableCell::new("18pt"),
132            TableCell::new("Calibri"),
133            TableCell::new("Medium Calibri Text").font_size(18).font_family("Calibri"),
134        ]),
135        TableRow::new(vec![
136            TableCell::new("24pt"),
137            TableCell::new("Times New Roman"),
138            TableCell::new("Large Times Text").font_size(24).font_family("Times New Roman"),
139        ]),
140        TableRow::new(vec![
141            TableCell::new("32pt"),
142            TableCell::new("Arial"),
143            TableCell::new("Extra Large Arial").font_size(32).font_family("Arial"),
144        ]),
145    ];
146
147    Table::new(
148        vec![vec![header_row], rows].concat(),
149        vec![2000000, 2500000, 3500000],
150        500000,
151        1500000,
152    )
153}
154
155fn create_combined_table() -> Table {
156    let header_cells = vec![
157        TableCell::new("Feature").bold().background_color("C0504D"),
158        TableCell::new("Styled Example").bold().background_color("C0504D"),
159    ];
160    let header_row = TableRow::new(header_cells);
161
162    let rows = vec![
163        TableRow::new(vec![
164            TableCell::new("Important Header"),
165            TableCell::new("Critical Data")
166                .bold()
167                .text_color("FFFFFF")
168                .background_color("C0504D")
169                .font_size(20),
170        ]),
171        TableRow::new(vec![
172            TableCell::new("Emphasis"),
173            TableCell::new("Highlighted Text")
174                .bold()
175                .italic()
176                .text_color("0000FF")
177                .font_size(18)
178                .font_family("Calibri"),
179        ]),
180        TableRow::new(vec![
181            TableCell::new("Warning"),
182            TableCell::new("Warning Message")
183                .bold()
184                .underline()
185                .text_color("FF6600")
186                .background_color("FFF4E6")
187                .font_size(16),
188        ]),
189        TableRow::new(vec![
190            TableCell::new("Success"),
191            TableCell::new("Success Indicator")
192                .bold()
193                .text_color("00AA00")
194                .background_color("E6F7E6")
195                .font_size(18)
196                .font_family("Arial"),
197        ]),
198    ];
199
200    Table::new(
201        vec![vec![header_row], rows].concat(),
202        vec![3000000, 5000000],
203        500000,
204        1500000,
205    )
206}
Source

pub fn from_data( data: Vec<Vec<&str>>, column_widths: Vec<u32>, x: u32, y: u32, ) -> Self

Create a table from raw data (2D string array)

Examples found in repository?
examples/table_generation.rs (lines 57-66)
56fn create_simple_table_example() -> Result<(), Box<dyn std::error::Error>> {
57    let table = Table::from_data(
58        vec![
59            vec!["Name", "Age"],
60            vec!["Alice", "30"],
61            vec!["Bob", "25"],
62        ],
63        vec![2000000, 2000000],
64        500000,
65        1500000,
66    );
67
68    let slides = vec![
69        SlideContent::new("Simple 2x2 Table")
70            .add_bullet("Table with basic structure")
71            .add_bullet("Headers and data rows"),
72        SlideContent::new("Table Data")
73            .table(table),
74    ];
75
76    let pptx_data = create_pptx_with_content("Simple Table", slides)?;
77    fs::write("examples/output/simple_table.pptx", pptx_data)?;
78    Ok(())
79}
Source

pub fn width(&self) -> u32

Calculate total table width

Source

pub fn height(&self) -> u32

Calculate total table height based on row heights

Source

pub fn row_count(&self) -> usize

Get the number of rows

Source

pub fn column_count(&self) -> usize

Get the number of columns

Trait Implementations§

Source§

impl Clone for Table

Source§

fn clone(&self) -> Table

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Table

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Table

§

impl RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl UnwindSafe for Table

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more