Commit 755ea146 authored by CharlieC's avatar CharlieC
Browse files

If date is outside range convert to an error and warn.

Resolves #1152

--HG--
branch : 2.6
parent e1f30808c5e8
......@@ -193,7 +193,13 @@ class WorkSheetParser(object):
value = _cast_number(value)
if style_id in self.date_formats:
data_type = 'd'
value = from_excel(value, self.epoch)
try:
value = from_excel(value, self.epoch)
except ValueError:
msg = "{0} has an invalid date".format(coordinate)
warn(msg)
data_type = "e"
value = "#VALUE!"
elif data_type == 's':
value = self.shared_strings[int(value)]
elif data_type == 'b':
......
......@@ -287,6 +287,23 @@ class TestWorksheetParser:
'style_id':0, 'value': datetime.datetime(2011, 12, 25, 14, 23, 55)}
def test_invalid_date(self, WorkSheetParser):
parser = WorkSheetParser
parser.epoch = CALENDAR_WINDOWS_1900
src = """
<c r="A1" t="n" s="29" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<v>2958466</v>
</c>
"""
element = fromstring(src)
cell = parser.parse_cell(element)
assert cell == {'column': 1, 'data_type': 'e', 'row': 1,
'style_id':29, 'value':"#VALUE!"}
def test_mac_date(self, WorkSheetParser):
parser = WorkSheetParser
parser.epoch = CALENDAR_MAC_1904
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment