Skip to content

Commit

Permalink
Merge dbb0505 into f2e188a
Browse files Browse the repository at this point in the history
  • Loading branch information
exer2k committed Jul 29, 2019
2 parents f2e188a + dbb0505 commit 4393553
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions tests/__init__.py
Expand Up @@ -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 title="test">
<row><cell type="date" date-fmt="%d.%m.%Y"></cell></row>
</sheet>
"""
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 = """
<sheet title="test">
Expand Down
8 changes: 6 additions & 2 deletions xml2xlsx/__init__.py
Expand Up @@ -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
Expand Down

0 comments on commit 4393553

Please sign in to comment.