Skip to content

BUG: Work-around openpyxl-2.1.0 NumberFormat removal #8352

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 1 commit into from
Closed
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions pandas/io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,20 +1029,20 @@ def _convert_to_alignment(cls, alignment_dict):
@classmethod
def _convert_to_number_format(cls, number_format_dict):
"""
Convert ``number_format_dict`` to an openpyxl v2 NumberFormat object.
Convert ``number_format_dict`` to an openpyxl v2.1.0 number format
initializer.
Parameters
----------
number_format_dict : dict
A dict with zero or more of the following keys.
'format_code'
'format_code' : str
Returns
-------
number_format : openpyxl.styles.NumberFormat
number_format : str
"""

from openpyxl.styles import NumberFormat

return NumberFormat(**number_format_dict)
# XXX: Only works with openpyxl-2.1.0
return number_format_dict['format_code']


@classmethod
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/tests/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ def test_to_excel_styleconverter(self):
alignment = styles.Alignment(horizontal='center', vertical='top')
fill_color = styles.Color(rgb='006666FF', tint=0.3)
fill = styles.PatternFill(patternType='solid', fgColor=fill_color)
number_format = styles.NumberFormat(format_code='0.00')
number_format = '0.00' # XXX: Only works with openpyxl-2.1.0
protection = styles.Protection(locked=True, hidden=False)

kw = _Openpyxl2Writer._convert_to_style_kwargs(hstyle)
Expand Down