add special case for numeric type cells with a date number format

This commit is contained in:
Thomas Fussell 2017-09-13 12:02:17 -04:00
parent 4c2c7a5859
commit 751599b44c
2 changed files with 8 additions and 1 deletions

View File

@ -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_<xlnt::cell::type>(cell, "Type")

View File

@ -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)