use crate::coordinate::{CellRef, Range, Row};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Table {
pub id: u32,
pub name: String,
pub display_name: String,
pub range: Range,
pub header_row_count: Option<u32>,
pub totals_row_count: Option<u32>,
pub auto_filter: Option<Range>,
pub columns: Vec<TableColumn>,
pub style: Option<TableStyle>,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct TableColumn {
pub id: u32,
pub name: String,
pub totals_row_function: Option<String>,
pub totals_row_label: Option<String>,
pub calculated_formula: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[expect(
clippy::struct_excessive_bools,
reason = "one field per attribute of <tableStyleInfo>; a bitfield would hide the format"
)]
pub struct TableStyle {
pub name: Option<String>,
pub show_first_column: bool,
pub show_last_column: bool,
pub show_row_stripes: bool,
pub show_column_stripes: bool,
}
impl Table {
#[must_use]
pub fn body(&self) -> Option<Range> {
let top = Row::new(
self.range
.start
.row
.index()
.checked_add(self.header_row_count.unwrap_or(1))?,
)?;
let bottom = Row::new(
self.range
.end
.row
.index()
.checked_sub(self.totals_row_count.unwrap_or(0))?,
)?;
if top > bottom {
return None;
}
Some(Range {
start: CellRef::new(self.range.start.col, top),
end: CellRef::new(self.range.end.col, bottom),
})
}
}