diff --git a/src/types/cell.rs b/src/types/cell.rs index 871ff93..cc91e45 100644 --- a/src/types/cell.rs +++ b/src/types/cell.rs @@ -114,6 +114,11 @@ where .map(|s| CellValue::String(s.to_owned())) .unwrap_or(CellValue::Empty), ) + } else if value.is_error() { + value + .get_error() + .map(|error| CellValue::String(error.to_string())) + .unwrap_or(CellValue::Empty) } else if value.is_bool() { value .get_bool() diff --git a/tests/data/error-cells.xls b/tests/data/error-cells.xls new file mode 100644 index 0000000..34d5f8f Binary files /dev/null and b/tests/data/error-cells.xls differ diff --git a/tests/data/error-cells.xlsx b/tests/data/error-cells.xlsx new file mode 100644 index 0000000..45149e3 Binary files /dev/null and b/tests/data/error-cells.xlsx differ diff --git a/tests/test_error_cells.py b/tests/test_error_cells.py new file mode 100644 index 0000000..644811b --- /dev/null +++ b/tests/test_error_cells.py @@ -0,0 +1,19 @@ +from pathlib import Path + +import pytest +from python_calamine import CalamineWorkbook + +DATA = Path(__file__).parent / "data" +COMMON_ERRORS = ["#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A"] + + +@pytest.mark.parametrize( + ("filename", "errors"), + [("error-cells.xlsx", COMMON_ERRORS), ("error-cells.xls", [*COMMON_ERRORS, "#DATA!"])], +) +def test_error_cells_keep_codes_in_both_sheet_apis(filename, errors): + with CalamineWorkbook.from_path(DATA / filename) as workbook: + sheet = workbook.get_sheet_by_name("Errors") + expected = [errors + ["", "#N/A"]] + assert list(sheet.iter_rows()) == expected + assert sheet.to_python() == expected