Skip to content

Commit bc3fcc6

Browse files
locojaydevwesm
locojaydev
authored andcommitted
test fix
1 parent 5759093 commit bc3fcc6

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

pandas/io/parsers.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ class CellStyleConverter(object):
19451945
"""
19461946

19471947
@staticmethod
1948-
def to_xls(style_dict):
1948+
def to_xls(style_dict, num_format_str=None):
19491949
"""
19501950
converts a style_dict to an xlwt style object
19511951
Parameters
@@ -1987,9 +1987,13 @@ def style_to_xlwt(item, firstlevel=True, field_sep=',', line_sep=';'):
19871987

19881988
if style_dict:
19891989
xlwt_stylestr = style_to_xlwt(style_dict)
1990-
return xlwt.easyxf(xlwt_stylestr, field_sep=',', line_sep=';')
1990+
style = xlwt.easyxf(xlwt_stylestr, field_sep=',', line_sep=';')
19911991
else:
1992-
return xlwt.XFStyle()
1992+
style = xlwt.XFStyle()
1993+
if num_format_str is not None:
1994+
style.num_format_str = num_format_str
1995+
1996+
return style
19931997

19941998
@staticmethod
19951999
def to_xlsx(style_dict):
@@ -2132,19 +2136,22 @@ def _writecells_xls(self, cells, sheet_name, startrow, startcol):
21322136
for cell in cells:
21332137
val = _conv_value(cell.val)
21342138

2139+
num_format_str = None
2140+
if isinstance(cell.val, datetime.datetime):
2141+
num_format_str = "YYYY-MM-DD HH:MM:SS"
2142+
if isinstance(cell.val, datetime.date):
2143+
num_format_str = "YYYY-MM-DD"
2144+
21352145
stylekey = json.dumps(cell.style)
2146+
if num_format_str:
2147+
stylekey += num_format_str
2148+
21362149
if stylekey in style_dict:
21372150
style = style_dict[stylekey]
21382151
else:
2139-
style = CellStyleConverter.to_xls(cell.style)
2152+
style = CellStyleConverter.to_xls(cell.style, num_format_str)
21402153
style_dict[stylekey] = style
21412154

2142-
if isinstance(val, datetime.datetime):
2143-
style.num_format_str = "YYYY-MM-DD HH:MM:SS"
2144-
elif isinstance(val, datetime.date):
2145-
style.num_format_str = "YYYY-MM-DD"
2146-
2147-
21482155
if cell.mergestart is not None and cell.mergeend is not None:
21492156
wks.write_merge(startrow + cell.row,
21502157
startrow + cell.mergestart,

0 commit comments

Comments
 (0)