pub struct ExcelTable {
pub id: u64,
pub name: String,
pub sheet_id: u64,
pub start_row: usize,
pub start_col: usize,
pub end_row: usize,
pub end_col: usize,
pub has_header_row: bool,
pub has_totals_row: bool,
pub columns: Vec<String>,
pub style_name: Option<String>,
pub has_insert_row: bool,
}Expand description
A named, rectangular range within a single worksheet, mirroring an Excel
Table (a.k.a. ListObject): a header row, a body of data rows, and an
optional totals row, all with stable per-column names that formulas can
reference via structured references (e.g. Sales[Amount]).
This is a distinct concept from a Sheet: elsewhere in this codebase a
Sheet is informally called a “table” (see Sheet::new’s default name
"table_1"), but an ExcelTable is a sub-range that lives on a sheet,
exactly like a real Excel Table can occupy only part of a worksheet.
Fields§
§id: u64Workbook-unique identifier, stable across renames.
name: StringThe table’s name, as a structured reference spells it. Unique workbook-wide and matched case-insensitively.
sheet_id: u64The sheet this table occupies part of.
start_row: usizeTopmost row of the range, 0-based – the header row when there is one.
start_col: usizeLeftmost column of the range, 0-based.
end_row: usizeBottommost row of the range, 0-based and inclusive – the totals row when there is one.
end_col: usizeRightmost column of the range, 0-based and inclusive.
has_header_row: boolWhether the first row is a header rather than data.
has_totals_row: boolWhether the last row is a totals row rather than data.
columns: Vec<String>Column names, in sheet-column order, one per column in
start_col..=end_col. Kept in sync with the header row’s cell text
(when has_header_row is true) by the CRUD methods in this file.
style_name: Option<String>Visual style theme name (e.g. “TableStyleMedium9”, “TableStyleLight1”, or custom theme)
has_insert_row: boolWhether the last row of the range is Excel’s insert row placeholder rather than data – i.e. the table has zero data rows.
This cannot be inferred from the extent, which is the surprise:
deleting a one-data-row table’s only row leaves ref at A1:C2 and
sets insertRow="1" in xl/tables/tableN.xml, so a zero-row table
and a table with one blank data row have identical bounds. Excel
tells them apart by this flag and so must we – ListObject’s
.DataBodyRange is Nothing and .ListRows.Count is 0 for the
former and a real range and 1 for the latter. Measured with
fuzz/vba_table_probe.py --empty, which is issue #11’s shape.
Implementations§
Source§impl ExcelTable
impl ExcelTable
Sourcepub fn set_style_name(&mut self, style_name: Option<String>)
pub fn set_style_name(&mut self, style_name: Option<String>)
Sets the table’s visual style, or clears it with None.
Sourcepub fn data_start_row(&self) -> usize
pub fn data_start_row(&self) -> usize
First row of the table’s actual data body (excludes the header row).
Sourcepub fn data_end_row(&self) -> usize
pub fn data_end_row(&self) -> usize
Last row of the table’s actual data body, excluding the totals row and Excel’s insert-row placeholder.
May be less than data_start_row() for a table with no data rows, so
callers building a range from the pair must handle the empty case
rather than assuming start..=end is non-empty. See
ExcelTable::data_row_count.
Sourcepub fn data_row_count(&self) -> usize
pub fn data_row_count(&self) -> usize
How many data rows the table actually has, which is 0 for a table sitting on its insert-row placeholder.
Use this rather than comparing data_start_row() with
data_end_row(): an empty table’s end is below its start, so the
subtraction underflows.
Sourcepub fn header_row(&self) -> Option<usize>
pub fn header_row(&self) -> Option<usize>
The header row’s sheet-row index, or None if the table has no
header.
Sourcepub fn totals_row(&self) -> Option<usize>
pub fn totals_row(&self) -> Option<usize>
The totals row’s sheet-row index, or None if the table has no
totals row.
Sourcepub fn local_column_index(&self, name: &str) -> Option<usize>
pub fn local_column_index(&self, name: &str) -> Option<usize>
Index (0-based, relative to the table’s own columns) of the column with the given name, matched case-insensitively as Excel does for structured references.
Trait Implementations§
Source§impl Clone for ExcelTable
impl Clone for ExcelTable
Source§fn clone(&self) -> ExcelTable
fn clone(&self) -> ExcelTable
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more