Skip to main content

wolfxl_core/
cell.rs

1use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
2
3#[derive(Debug, Clone, PartialEq)]
4pub enum CellValue {
5    Empty,
6    String(String),
7    Int(i64),
8    Float(f64),
9    Bool(bool),
10    Date(NaiveDate),
11    DateTime(NaiveDateTime),
12    Time(NaiveTime),
13    Error(String),
14}
15
16impl CellValue {
17    pub fn is_empty(&self) -> bool {
18        matches!(self, CellValue::Empty)
19    }
20
21    pub fn type_name(&self) -> &'static str {
22        match self {
23            CellValue::Empty => "empty",
24            CellValue::String(_) => "string",
25            CellValue::Int(_) => "int",
26            CellValue::Float(_) => "float",
27            CellValue::Bool(_) => "bool",
28            CellValue::Date(_) => "date",
29            CellValue::DateTime(_) => "datetime",
30            CellValue::Time(_) => "time",
31            CellValue::Error(_) => "error",
32        }
33    }
34}
35
36#[derive(Debug, Clone)]
37pub struct Cell {
38    pub value: CellValue,
39    /// Excel number format string applied to this cell, if any.
40    /// Examples: "0.00", "$#,##0.00", "0%", "yyyy-mm-dd".
41    pub number_format: Option<String>,
42}
43
44impl Cell {
45    pub fn empty() -> Self {
46        Self {
47            value: CellValue::Empty,
48            number_format: None,
49        }
50    }
51}