-
-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More pytest-like test_styler_to_excel; enhancements to xlwt
- Loading branch information
Showing
4 changed files
with
178 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1468,6 +1468,37 @@ def write_cells(self, cells, sheet_name=None, startrow=0, startcol=0, | |
startcol + cell.col, | ||
val, style) | ||
|
||
@classmethod | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jnothman
via email
Author
Contributor
|
||
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=';'): | ||
|
@@ -1476,16 +1507,19 @@ def _style_to_xlwt(cls, item, firstlevel=True, field_sep=',', | |
hstyle = {"font": {"bold": True}, | ||
"border": {"top": "thin", | ||
"right": "thin", | ||
"right": {"style": "thin", "color": "red"}, | ||
"bottom": "thin", | ||
"left": "thin"}, | ||
"align": {"horiz": "center"}} | ||
will be converted to | ||
font: bold on; \ | ||
border: top thin, right thin, bottom thin, left thin; \ | ||
border: top thin, right thin, right_color red, \ | ||
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()] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hmm what is the purpose of this?