From 751599b44c32a4c96be6b95ebcea57091e8c6e5d Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Wed, 13 Sep 2017 12:02:17 -0400 Subject: [PATCH] add special case for numeric type cells with a date number format --- python/xlntpyarrow.lib.cpp | 4 ++++ python/xlntpyarrow/__init__.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/python/xlntpyarrow.lib.cpp b/python/xlntpyarrow.lib.cpp index 14c90271..f1eb4e78 100644 --- a/python/xlntpyarrow.lib.cpp +++ b/python/xlntpyarrow.lib.cpp @@ -427,6 +427,10 @@ PYBIND11_MODULE(lib, m) .def("column", [](xlnt::cell &cell) { return cell.column().index; + }) + .def("format_is_date", [](xlnt::cell &cell) + { + return cell.has_format() && cell.number_format().is_date_format(); }); pybind11::enum_(cell, "Type") diff --git a/python/xlntpyarrow/__init__.py b/python/xlntpyarrow/__init__.py index 8cf24f85..c50f9d08 100644 --- a/python/xlntpyarrow/__init__.py +++ b/python/xlntpyarrow/__init__.py @@ -63,7 +63,10 @@ def xlsx2arrow(io, sheetname): continue elif cell.row() == 2: column_name = column_names[cell.column() - 1] - fields.append(pa.field(column_name, COLUMN_TYPE_FIELD[type]())) + if type == xpa.Cell.Type.Number and cell.format_is_date(): + fields.append(pa.field(column_name, pa.date32)) + else: + fields.append(pa.field(column_name, COLUMN_TYPE_FIELD[type]())) first_batch.append(cell_to_pyarrow_array(cell, fields[-1].type)) if cell.column() == max_column: schema = pa.schema(fields)