diff --git a/tests/__init__.py b/tests/__init__.py index 84465f2..1dd131d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -171,6 +171,17 @@ def test_cell_type_date(self): ws = wb["test"] self.assertEquals(ws["A1"].value.date(), date(1981, 1, 24)) + def test_empty_cell_type_date(self): + template = """ + + + + """ + sheet = io.BytesIO(xml2xlsx(template)) + wb = load_workbook(sheet) + ws = wb['test'] + self.assertEquals(ws['A1'].value, None) + def test_cell_number_format(self): template = """ diff --git a/xml2xlsx/__init__.py b/xml2xlsx/__init__.py index f380d79..6b6301f 100644 --- a/xml2xlsx/__init__.py +++ b/xml2xlsx/__init__.py @@ -212,8 +212,12 @@ def end(self, tag): except InvalidOperation: pass elif self._cell_type == 'date': - self._cell.value = datetime.strptime( - self._cell.value, self._cell_date_format).date() + if self._cell.value: + try: + self._cell.value = datetime.strptime( + self._cell.value, self._cell_date_format).date() + except TypeError: + pass self._row_buf.append(self._cell) self._cell = None self._col += 1