Skip to content

Commit 54954dc

Browse files
committed
Merge branch 'devel'
2 parents 4d8d01c + b25d532 commit 54954dc

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#### 3.0.4
2+
* Fixed style "shifts" when using `read_style=True` and `header=None` with `StyleFrame.read_excel`. Fixes github issue #80
3+
14
#### 3.0.3
25
No longer relying on openpyxl's colors definition. Related to github issue #73
36

styleframe/style_frame.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,20 @@ def _read_style():
199199
col_index_in_excel += 1 # Move next to excel indices column
200200

201201
sf.columns[col_index].style = get_style_object(row=1, column=col_index_in_excel)
202-
for row_index, sf_index in enumerate(sf.index, start=2):
202+
for row_index, sf_index in enumerate(sf.index, start=start_row_index):
203203
sf.at[sf_index, col_name].style = get_style_object(row=row_index, column=col_index_in_excel)
204204
sf._rows_height[row_index] = sheet.row_dimensions[row_index].height
205205

206206
sf._columns_width[col_name] = sheet.column_dimensions[sf._get_column_as_letter(sheet, col_name)].width
207207

208208
sheet_name = kwargs.pop('sheetname', sheet_name)
209+
header_arg = kwargs.get('header', 0)
210+
if read_style and isinstance(header_arg, Iterable):
211+
raise ValueError('Not supporting multiple index columns with read style.')
212+
if header_arg is None:
213+
start_row_index = 1
214+
else:
215+
start_row_index = header_arg + 2
209216
index_col = kwargs.get('index_col')
210217
excel_index_col = index_col + 1 if index_col is not None else None
211218
if read_style and isinstance(excel_index_col, Iterable):

styleframe/tests/style_frame_tests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,22 @@ def test_read_excel_with_style_comments_styler_objects(self):
411411
for row_in_excel, row_in_self in zip(rows_in_excel, rows_in_self)
412412
for excel_cell, self_cell in zip(row_in_excel[1:], row_in_self[1:])))
413413

414+
def test_read_excel_with_style_header_arg_none(self):
415+
self.sf = StyleFrame({0: ['A1', 'A2', 'A3', 'A4', 'A5']})
416+
self.sf.apply_style_by_indexes(self.sf[self.sf.data_df[0].isin(('A2', 'A5'))], Styler(bold=True))
417+
self.export_and_get_default_sheet(save=True)
418+
sf_from_excel = StyleFrame.read_excel(TEST_FILENAME, read_style=True, header=None)
419+
# making sure content is the same
420+
self.assertTrue(all(list(self.sf[col]) == list(sf_from_excel[col])[1:] for col in self.sf.columns))
421+
422+
rows_in_excel = list(sf_from_excel.data_df.itertuples())
423+
rows_in_self = self.sf.data_df.itertuples()
424+
425+
# making sure styles are the same
426+
self.assertTrue(all(excel_cell.style == self_cell.style
427+
for row_in_excel, row_in_self in zip(rows_in_excel[1:], rows_in_self)
428+
for excel_cell, self_cell in zip(row_in_excel[1:], row_in_self[1:])))
429+
414430
def test_read_excel_template_equal_boundaries(self):
415431
template_sf = StyleFrame(
416432
obj={

styleframe/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_all_versions():
1717
return _versions_
1818

1919

20-
_version_ = '3.0.3'
20+
_version_ = '3.0.4'
2121
_python_version_ = get_python_version()
2222
_pandas_version_ = get_pandas_version()
2323
_openpyxl_version_ = get_openpyxl_version()

0 commit comments

Comments
 (0)