Skip to main content

Table

Struct Table 

Source
pub struct Table { /* private fields */ }
Expand description

A table of plain text to insert in place of a placeholder paragraph.

Rows may have different lengths: shorter rows are padded with empty cells, so the table has as many cells as its number of rows times the length of its longest row. One row of 2,000 cells among 2,000 rows of one cell makes 4 million cells, so bound the length of the longest row when rows come from untrusted input. Word rejects rows and tables without cells, so a table always has at least one column, and a table with no rows gets one empty row: Table::new with no rows yields a single empty cell.

In cell text, line breaks (\n, \r\n or \r) become line breaks inside the cell and tabs become tab characters. Characters that XML can’t represent (most control characters) are dropped.

use ciclostile::{Length, Table};

let table = Table::new([
    ["Item", "Quantity"],
    ["Apples", "3"],
    ["Pears", "12"],
])
.header(true)
.column_widths([Length::from_cm(8.0), Length::from_cm(3.0)]);

Implementations§

Source§

impl Table

Source

pub fn new<R, C, S>(rows: R) -> Self
where R: IntoIterator<Item = C>, C: IntoIterator<Item = S>, S: Into<String>,

Create a table from its rows of cell texts.

Rows may have different lengths: shorter rows are padded with empty cells, so the table has as many cells as rows times the length of the longest row. With no rows the table is a single empty cell, and rows that are all empty get one empty cell each.

Source

pub fn style(self, style_id: impl Into<String>) -> Self

Apply a table style defined in the template, by its style id.

The id is the w:styleId in the template’s styles.xml, which can differ from the name Word shows: the built-in “Table Grid” style has the id TableGrid. A styled table gets no borders of its own, so the style decides them. If the template doesn’t define the style, word processors fall back to the document’s default table style, which usually has no borders. An empty id is the same as no style.

Default: no style, with thin single borders around and between all cells

Source

pub fn column_widths(self, widths: impl IntoIterator<Item = Length>) -> Self

Set the column widths, from the first column on.

The columns then keep these widths whatever their content (fixed layout), and the table is as wide as their sum. Widths are written in twips (1/20 point), rounded to the nearest one. Widths beyond the number of columns are ignored. Columns without a width share what the given widths leave of the default 17 cm, but never get less than with no widths at all (17 cm split evenly between all columns). An empty list is the same as no widths.

Default: the table spans the full text width, and its columns start out equal and adapt to their content

Source

pub fn header(self, header: bool) -> Self

Mark the first row as a header row: its text is bold, and it repeats at the top of every page the table spans.

Default: false

Trait Implementations§

Source§

impl Clone for Table

Source§

fn clone(&self) -> Self

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 Table

Source§

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

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

impl Eq for Table

Source§

impl PartialEq for Table

Source§

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

Auto Trait Implementations§

§

impl Freeze for Table

§

impl RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl UnsafeUnpin 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, 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.