@@ -1945,7 +1945,7 @@ class CellStyleConverter(object):
1945
1945
"""
1946
1946
1947
1947
@staticmethod
1948
- def to_xls (style_dict ):
1948
+ def to_xls (style_dict , num_format_str = None ):
1949
1949
"""
1950
1950
converts a style_dict to an xlwt style object
1951
1951
Parameters
@@ -1987,9 +1987,13 @@ def style_to_xlwt(item, firstlevel=True, field_sep=',', line_sep=';'):
1987
1987
1988
1988
if style_dict :
1989
1989
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 = ';' )
1991
1991
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
1993
1997
1994
1998
@staticmethod
1995
1999
def to_xlsx (style_dict ):
@@ -2132,19 +2136,22 @@ def _writecells_xls(self, cells, sheet_name, startrow, startcol):
2132
2136
for cell in cells :
2133
2137
val = _conv_value (cell .val )
2134
2138
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
+
2135
2145
stylekey = json .dumps (cell .style )
2146
+ if num_format_str :
2147
+ stylekey += num_format_str
2148
+
2136
2149
if stylekey in style_dict :
2137
2150
style = style_dict [stylekey ]
2138
2151
else :
2139
- style = CellStyleConverter .to_xls (cell .style )
2152
+ style = CellStyleConverter .to_xls (cell .style , num_format_str )
2140
2153
style_dict [stylekey ] = style
2141
2154
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
-
2148
2155
if cell .mergestart is not None and cell .mergeend is not None :
2149
2156
wks .write_merge (startrow + cell .row ,
2150
2157
startrow + cell .mergestart ,
0 commit comments