Commit 5ecf8fbc authored by CharlieC's avatar CharlieC
Browse files

Handle rowBreak and colBreak more explicitly and demote ws.page_breaks to a property.

Resolves #1368

--HG--
branch : 3.0
parent acf24c2bec0f
......@@ -103,7 +103,8 @@ class WorkSheetParser(object):
self.formatting = []
self.legacy_drawing = None
self.merged_cells = None
self.page_breaks = []
self.row_breaks = RowBreak()
self.col_breaks = ColBreak()
def parse(self):
......@@ -132,6 +133,7 @@ class WorkSheetParser(object):
TABLE_TAG: ('tables', TablePartList),
HYPERLINK_TAG: ('hyperlinks', HyperlinkList),
MERGE_TAG: ('merged_cells', MergeCells),
}
it = iterparse(self.source)
......@@ -300,17 +302,19 @@ class WorkSheetParser(object):
def parse_row_breaks(self, element):
brk = RowBreak.from_tree(element)
self.page_breaks.append(brk)
self.row_breaks = brk
def parse_col_breaks(self, element):
brk = ColBreak.from_tree(element)
self.page_breaks.append(brk)
self.col_breaks = brk
def parse_custom_views(self, element):
# clear page_breaks to avoid duplication
self.page_breaks = []
# clear page_breaks to avoid duplication which Excel doesn't like
# basically they're ignored in custom views
self.row_breaks = RowBreak()
self.col_breaks = ColBreak()
class WorksheetReader(object):
......@@ -395,7 +399,7 @@ class WorksheetReader(object):
for k in ('print_options', 'page_margins', 'page_setup',
'HeaderFooter', 'auto_filter', 'data_validations',
'sheet_properties', 'views', 'sheet_format',
'page_breaks', 'scenarios', 'legacy_drawing'):
'row_breaks', 'col_breaks', 'scenarios', 'legacy_drawing'):
v = getattr(self.parser, k, None)
if v is not None:
setattr(self.ws, k, v)
......
......@@ -234,7 +234,7 @@ class WorksheetWriter:
def write_breaks(self):
brks = self.ws.page_breaks
brks = (self.ws.row_breaks, self.ws.col_breaks)
for brk in brks:
if brk:
self.xf.send(brk.to_tree())
......
......@@ -672,7 +672,7 @@ class TestWorksheetParser:
el = fromstring(src)
parser.parse_row_breaks(el)
assert parser.page_breaks == [expected_pagebreak]
assert parser.row_breaks == expected_pagebreak
def test_col_break(self, WorkSheetParser):
......@@ -688,7 +688,7 @@ class TestWorksheetParser:
el = fromstring(src)
parser.parse_col_breaks(el)
assert parser.page_breaks == [expected_pagebreak]
assert parser.col_breaks == expected_pagebreak
def test_scenarios(self, WorkSheetParser):
......@@ -746,7 +746,7 @@ class TestWorksheetParser:
parser.source = BytesIO(src)
for _ in parser.parse():
pass
assert parser.page_breaks == []
assert parser.row_breaks == RowBreak()
@pytest.fixture
......
......@@ -102,7 +102,6 @@ class Worksheet(_WorkbookChild):
default_factory=self._add_column)
self.row_breaks = RowBreak()
self.col_breaks = ColBreak()
self.page_breaks = (self.row_breaks, self.col_breaks)
self._cells = {}
self._charts = []
self._images = []
......@@ -150,6 +149,12 @@ class Worksheet(_WorkbookChild):
def active_cell(self):
return self.sheet_view.selection[0].activeCell
@property
def page_breaks(self):
return (self.row_breaks, self.col_breaks) # legacy, remove at some point
@property
def show_gridlines(self):
return self.sheet_view.showGridLines
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment