Skip to content

Commit 2a862ef

Browse files
authored
Fix #81 read excel as template headers height
* Fixes #81 read read excel as template headers height * remove unsed kwargs * reorder tests * remove print from tests
1 parent b25d532 commit 2a862ef

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

styleframe/style_frame.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ def _read_style():
190190
raise TypeError("'sheet_name' must be a string or int, got {} instead".format(type(sheet_name)))
191191
theme_colors = _get_scheme_colors_from_excel(wb)
192192

193+
# Set the headers row height
194+
if header_arg is not None:
195+
headers_row_idx = header_arg + 1
196+
sf._rows_height[headers_row_idx] = sheet.row_dimensions[headers_row_idx].height
197+
193198
get_style_object = partial(_get_style_object, sheet=sheet, theme_colors=theme_colors)
194199
for col_index, col_name in enumerate(sf.columns):
195200
col_index_in_excel = col_index + 1

styleframe/tests/style_frame_tests.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,30 @@ def test_read_excel_with_style_header_arg_none(self):
427427
for row_in_excel, row_in_self in zip(rows_in_excel[1:], rows_in_self)
428428
for excel_cell, self_cell in zip(row_in_excel[1:], row_in_self[1:])))
429429

430+
def test_read_excel_rows_height(self):
431+
self.sf.set_row_height(rows=1, height=25)
432+
self.sf.set_row_height(rows=2, height=15)
433+
self.export_and_get_default_sheet(save=True)
434+
sf_from_excel = StyleFrame.read_excel(TEST_FILENAME, read_style=True)
435+
436+
# Assert the number of rows with height is the length of our data plus 1 for headers row
437+
self.assertEqual(len(sf_from_excel._rows_height), len(self.sf) + 1)
438+
self.assertEqual(sf_from_excel._rows_height[1], 25)
439+
self.assertEqual(sf_from_excel._rows_height[2], 15)
440+
self.assertEqual(sf_from_excel._rows_height[3], None)
441+
self.assertEqual(sf_from_excel._rows_height[4], None)
442+
443+
def test_read_excel_columns_width(self):
444+
self.sf.set_column_width(columns='a', width=25)
445+
self.sf.set_column_width(columns='b', width=15)
446+
self.export_and_get_default_sheet(save=True)
447+
sf_from_excel = StyleFrame.read_excel(TEST_FILENAME, read_style=True)
448+
449+
# Assert the number of rows with height is the length of our data plus 1 for headers row
450+
self.assertEqual(len(sf_from_excel._columns_width), len(self.sf.columns))
451+
self.assertEqual(sf_from_excel._columns_width['a'], 25)
452+
self.assertEqual(sf_from_excel._columns_width['b'], 15)
453+
430454
def test_read_excel_template_equal_boundaries(self):
431455
template_sf = StyleFrame(
432456
obj={

0 commit comments

Comments
 (0)