diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index 5c331de..2c9b9fa 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -10,6 +10,8 @@ use xlsx::import; mod types; +use crate::types::PyCellType; + create_exception!(_ironcalc, WorkbookError, PyException); /// This is a model implementing the 'raw' API @@ -58,6 +60,21 @@ impl PyModel { // Get values + /// Get raw value + pub fn get_cell_content(&self, sheet: u32, row: i32, column: i32) -> PyResult { + self.model + .get_cell_content(sheet, row, column) + .map_err(|e| WorkbookError::new_err(e.to_string())) + } + + /// Get cell type + pub fn get_cell_type(&self, sheet: u32, row: i32, column: i32) -> PyResult { + self.model + .get_cell_type(sheet, row, column) + .map(|cell_type| cell_type.into()) + .map_err(|e| WorkbookError::new_err(e.to_string())) + } + /// Get formatted value pub fn get_formatted_cell_value(&self, sheet: u32, row: i32, column: i32) -> PyResult { self.model diff --git a/bindings/python/src/types.rs b/bindings/python/src/types.rs index c2f2aef..a5cf5a5 100644 --- a/bindings/python/src/types.rs +++ b/bindings/python/src/types.rs @@ -1,6 +1,6 @@ use pyo3::prelude::*; use xlsx::base::types::{ - Alignment, Border, BorderItem, BorderStyle, Fill, Font, FontScheme, HorizontalAlignment, Style, + Alignment, Border, BorderItem, BorderStyle, Fill, Font, FontScheme, HorizontalAlignment, Style, CellType, VerticalAlignment, }; @@ -161,6 +161,17 @@ pub struct PyFill { pub bg_color: Option, } +#[pyclass(eq, eq_int)] +#[derive(PartialEq, Clone)] +pub enum PyCellType { + Number = 1, + Text = 2, + LogicalValue = 4, + ErrorValue = 16, + Array = 64, + CompoundData = 128, +} + // Conversions from references to Py* types to non-Py types // Enums @@ -426,3 +437,31 @@ impl From