Skip to content

‘use_openpyxl_styles’ in ‘read_excel’ makes ‘to_excel’ back fail #67

@mjozan

Description

@mjozan

Python version : 3.7.5
Openpyxl : 3.0.3
Pandas : 1.0.3
StyleFrame : 2.0.5

Hello

I am trying to read the style of a really simple excel and save it back to another excel with this code (the error only happens when setting use_openpyxl_styles to True:

tests_dir = os.path.dirname(__file__)
TEST_FILENAME = os.path.join(tests_dir, 'Book10.xlsx')
TEST_FILENAME2 = os.path.join(tests_dir, 'Book11.xlsx')
sf_from_excel = StyleFrame.StyleFrame.read_excel(TEST_FILENAME, read_style=True, sheet_name='Sheet1', use_openpyxl_styles=True)
ew = StyleFrame.StyleFrame.ExcelWriter(TEST_FILENAME2)
sf_from_excel.to_excel(ew)
ew.save()

However, I get this error:

Traceback (most recent call last):
  File “test.py", line 20, in <module>
    test()
  File "test.py.py", line 16, in test
    sf_from_excel.to_excel(ew)
  File "/Users/homefolder/Documents/teststyle/StyleFrame/StyleFrame/style_frame.py", line 359, in to_excel
    column_header_cell.style = style_to_apply
  File "/Users/homefolder/Documents/teststyle/StyleFrame/styleframeenv/lib/python3.7/site-packages/openpyxl/styles/styleable.py", line 85, in __set__
    raise ValueError("{0} is not a known style".format(value))
ValueError: <Cell 'Sheet1'.A1> is not a known style

The value <Cell 'Sheet1'.A1> when reading is set here:

column_cell = sheet.cell(row=1, column=col_index)
if use_openpyxl_styles:

And the error when writing happens here :

except AttributeError:
style_to_apply = column.style
column_header_cell = sheet.cell(row=startrow + 1, column=col_index + startcol + 1)
column_header_cell.style = style_to_apply

The error is originally raised here :

https://github.com/ArthurWatier/top_affinite/blob/36286aa256b283166382dd4c1041bc6e3775e781/venv/lib/python3.5/site-packages/openpyxl/styles/styleable.py#L81

Could you help me solve this error please? Thank you for your answer.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions