Skip to content

Commit

Permalink
Revert changes to xlwt
Browse files Browse the repository at this point in the history
  • Loading branch information
jnothman committed Apr 19, 2017
1 parent de53808 commit 836f39e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 41 deletions.
38 changes: 2 additions & 36 deletions pandas/io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,37 +1468,6 @@ def write_cells(self, cells, sheet_name=None, startrow=0, startcol=0,
startcol + cell.col,
val, style)

@classmethod
def _tweak_style(cls, item):
item = item.copy()
for k in ['top', 'right', 'bottom', 'left']:
if k not in item:
continue
side = item[k]
if not hasattr(side, 'items'):
continue
color = side.get('color') or side.get('colour')
if color is not None:
item[k + '_color'] = color
if side.get('style'):
item[k] = side['style']
if 'fill' in item and 'pattern' not in item:
fill = item.pop('fill')
item['pattern'] = {}
for k in ['patternType', 'patterntype', 'fill_type']:
if k in fill:
item['pattern']['pattern'] = fill[k]
break
for k in ['fgColor', 'fgcolor', 'start_color']:
if k in fill:
item['pattern']['fore_color'] = fill[k]
break
for k in ['bgColor', 'bgcolor', 'end_color']:
if k in fill:
item['pattern']['back_color'] = fill[k]
break
return item

@classmethod
def _style_to_xlwt(cls, item, firstlevel=True, field_sep=',',
line_sep=';'):
Expand All @@ -1507,19 +1476,16 @@ def _style_to_xlwt(cls, item, firstlevel=True, field_sep=',',
hstyle = {"font": {"bold": True},
"border": {"top": "thin",
"right": {"style": "thin", "color": "red"},
"right": "thin",
"bottom": "thin",
"left": "thin"},
"align": {"horiz": "center"}}
will be converted to
font: bold on; \
border: top thin, right thin, right_color red, \
bottom thin, left thin; \
border: top thin, right thin, bottom thin, left thin; \
align: horiz center;
"""
if hasattr(item, 'items'):
item = cls._tweak_style(item)

if firstlevel:
it = ["%s: %s" % (key, cls._style_to_xlwt(value, False))
for key, value in item.items()]
Expand Down
9 changes: 4 additions & 5 deletions pandas/tests/io/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2355,22 +2355,21 @@ def check_called(func):


@pytest.mark.parametrize('engine', [
'xlwt',
pytest.mark.xfail('xlwt', reason='xlwt does not support '
'openpyxl-compatible style dicts'),
'xlsxwriter',
'openpyxl',
])
def test_styler_to_excel(engine):
def style(df):
# XXX: RGB colors not supported in xlwt
return DataFrame([['font-weight: bold', '', ''],
(['', '', ''] if engine == 'xlwt'
else ['', 'color: blue', '']),
['', 'color: blue', ''],
['', '', 'text-decoration: underline'],
['border-style: solid', '', ''],
['', 'font-style: italic', ''],
['', '', 'text-align: right'],
(['', '', ''] if engine == 'xlwt'
else ['background-color: red', '', '']),
['background-color: red', '', ''],
['', '', ''],
['', '', ''],
['', '', '']],
Expand Down

0 comments on commit 836f39e

Please sign in to comment.