Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
openpyxl
openpyxl
Commits
ab27cdaab375
Commit
755ea146
authored
Jan 04, 2019
by
CharlieC
Browse files
If date is outside range convert to an error and warn.
Resolves
#1152
--HG-- branch : 2.6
parent
e1f30808c5e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
openpyxl/worksheet/_reader.py
View file @
ab27cdaa
...
...
@@ -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'
:
...
...
openpyxl/worksheet/tests/test_reader.py
View file @
ab27cdaa
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment