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
impl Table
Sourcepub fn new<R, C, S>(rows: R) -> Self
pub fn new<R, C, S>(rows: R) -> Self
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.
Sourcepub fn style(self, style_id: impl Into<String>) -> Self
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
Sourcepub fn column_widths(self, widths: impl IntoIterator<Item = Length>) -> Self
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