Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/types/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Binary file added tests/data/error-cells.xls
Binary file not shown.
Binary file added tests/data/error-cells.xlsx
Binary file not shown.
19 changes: 19 additions & 0 deletions tests/test_error_cells.py
Original file line number Diff line number Diff line change
@@ -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