use std::collections::HashMap;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum Align {
#[default]
Left,
Center,
Right,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum NumberFormat {
#[default]
Plain,
Currency,
}
#[derive(Clone, Debug, Default)]
pub struct Style {
pub bold: bool,
pub align: Align,
pub number_format: NumberFormat,
pub fill: Option<u32>,
pub border_top: bool,
pub font_size: Option<f32>,
}
impl Style {
pub fn new() -> Self {
Style::default()
}
pub fn bold(mut self) -> Self {
self.bold = true;
self
}
pub fn align(mut self, a: Align) -> Self {
self.align = a;
self
}
pub fn currency(mut self) -> Self {
self.number_format = NumberFormat::Currency;
self
}
pub fn fill(mut self, rgb: u32) -> Self {
self.fill = Some(rgb);
self
}
pub fn border_top(mut self) -> Self {
self.border_top = true;
self
}
pub fn size(mut self, pt: f32) -> Self {
self.font_size = Some(pt);
self
}
}
#[derive(Clone, Debug)]
pub enum Content {
Literal(String),
Text(String),
Expr(String),
Empty,
}
#[derive(Clone, Debug)]
pub struct CellSpec {
pub content: Content,
pub style: Style,
pub colspan: u16,
}
impl CellSpec {
pub fn new(content: Content) -> Self {
CellSpec {
content,
style: Style::new(),
colspan: 1,
}
}
pub fn literal(s: impl Into<String>) -> Self {
CellSpec::new(Content::Literal(s.into()))
}
pub fn text(s: impl Into<String>) -> Self {
CellSpec::new(Content::Text(s.into()))
}
pub fn expr(s: impl Into<String>) -> Self {
CellSpec::new(Content::Expr(s.into()))
}
pub fn empty() -> Self {
CellSpec::new(Content::Empty)
}
pub fn style(mut self, style: Style) -> Self {
self.style = style;
self
}
pub fn span(mut self, n: u16) -> Self {
self.colspan = n.max(1);
self
}
}
#[derive(Clone, Debug, Default)]
pub struct RowSpec {
pub cells: Vec<CellSpec>,
pub banded: bool,
}
impl RowSpec {
pub fn new(cells: Vec<CellSpec>) -> Self {
RowSpec {
cells,
banded: false,
}
}
pub fn banded(mut self) -> Self {
self.banded = true;
self
}
}
#[derive(Clone, Debug, Default)]
pub struct Band {
pub rows: Vec<RowSpec>,
pub accumulate: Vec<(String, String)>,
}
#[derive(Clone, Debug)]
pub struct ColumnSpec {
pub xlsx_width: f64,
pub pdf_width: f64,
}
#[derive(Clone, Debug, Default)]
pub struct Template {
pub name: String,
pub columns: Vec<ColumnSpec>,
pub fields: HashMap<String, Vec<String>>,
pub bands: HashMap<String, Band>,
}