Skip to content

to_execl xlwt fails on large files #2445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import pandas.lib as lib
import pandas._parser as _parser
from pandas.tseries.period import Period
import json


class DateConversionError(Exception):
pass
Expand Down Expand Up @@ -1929,7 +1931,7 @@ class CellStyleConverter(object):
"""

@staticmethod
def to_xls(style_dict):
def to_xls(style_dict, num_format_str=None):
"""
converts a style_dict to an xlwt style object
Parameters
Expand Down Expand Up @@ -1971,9 +1973,13 @@ def style_to_xlwt(item, firstlevel=True, field_sep=',', line_sep=';'):

if style_dict:
xlwt_stylestr = style_to_xlwt(style_dict)
return xlwt.easyxf(xlwt_stylestr, field_sep=',', line_sep=';')
style = xlwt.easyxf(xlwt_stylestr, field_sep=',', line_sep=';')
else:
return xlwt.XFStyle()
style = xlwt.XFStyle()
if num_format_str is not None:
style.num_format_str = num_format_str

return style

@staticmethod
def to_xlsx(style_dict):
Expand Down Expand Up @@ -2111,13 +2117,26 @@ def _writecells_xls(self, cells, sheet_name, startrow, startcol):
wks = self.book.add_sheet(sheet_name)
self.sheets[sheet_name] = wks

style_dict = {}

for cell in cells:
val = _conv_value(cell.val)
style = CellStyleConverter.to_xls(cell.style)
if isinstance(val, datetime.datetime):
style.num_format_str = "YYYY-MM-DD HH:MM:SS"
elif isinstance(val, datetime.date):
style.num_format_str = "YYYY-MM-DD"

num_format_str = None
if isinstance(cell.val, datetime.datetime):
num_format_str = "YYYY-MM-DD HH:MM:SS"
if isinstance(cell.val, datetime.date):
num_format_str = "YYYY-MM-DD"

stylekey = json.dumps(cell.style)
if num_format_str:
stylekey += num_format_str

if stylekey in style_dict:
style = style_dict[stylekey]
else:
style = CellStyleConverter.to_xls(cell.style, num_format_str)
style_dict[stylekey] = style

if cell.mergestart is not None and cell.mergeend is not None:
wks.write_merge(startrow + cell.row,
Expand Down