Commit 00494170 authored by CharlieC's avatar CharlieC
Browse files

Use explicit classes for RowBreak and ColBreak

Resolves #1197 and related.

--HG--
branch : 2.6
parent 64bf74942ea1
......@@ -35,7 +35,7 @@ from .header_footer import HeaderFooter
from .hyperlink import HyperlinkList
from .merge import MergeCells
from .page import PageMargins, PrintOptions, PrintPageSetup
from .pagebreak import PageBreak
from .pagebreak import RowBreak, ColBreak
from .protection import SheetProtection
from .scenario import ScenarioList
from .views import SheetViewList
......@@ -114,8 +114,8 @@ class WorkSheetParser(object):
EXT_TAG: self.parse_extensions,
CF_TAG: self.parse_formatting,
LEGACY_TAG: self.parse_legacy,
ROW_BREAK_TAG: self.parse_breaks,
COL_BREAK_TAG: self.parse_breaks,
ROW_BREAK_TAG: self.parse_row_breaks,
COL_BREAK_TAG: self.parse_col_breaks,
}
properties = {
......@@ -301,8 +301,13 @@ class WorkSheetParser(object):
self.legacy_drawing = obj.id
def parse_breaks(self, element):
brk = PageBreak.from_tree(element)
def parse_row_breaks(self, element):
brk = RowBreak.from_tree(element)
self.page_breaks.append(brk)
def parse_col_breaks(self, element):
brk = ColBreak.from_tree(element)
self.page_breaks.append(brk)
......
......@@ -80,3 +80,11 @@ class PageBreak(Serialisable):
brk = Break(id=self.count+1)
vals.append(brk)
self.brk = vals
RowBreak = PageBreak
class ColBreak(PageBreak):
tagname = "colBreaks"
......@@ -17,7 +17,7 @@ from openpyxl.styles import Border
from openpyxl.styles.differential import DifferentialStyle
from openpyxl.formula.translate import Translator
from ..worksheet import Worksheet
from ..pagebreak import Break, PageBreak
from ..pagebreak import Break, RowBreak, ColBreak
from ..scenario import ScenarioList, Scenario, InputCells
@pytest.mark.parametrize("value, expected",
......@@ -646,21 +646,34 @@ class TestWorksheetParser:
assert parser.auto_filter.sortState.ref == "A2:AM3269"
def test_page_break(self, WorkSheetParser):
def test_page_row_break(self, WorkSheetParser):
src = b"""
<sheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<rowBreaks count="1" manualBreakCount="1">
<brk id="15" man="1" max="16383" min="0"/>
</rowBreaks>
</sheet>
<rowBreaks count="1" manualBreakCount="1" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<brk id="15" man="1" max="16383" min="0"/>
</rowBreaks>
"""
expected_pagebreak = PageBreak()
expected_pagebreak = RowBreak()
expected_pagebreak.append(Break(id=15))
parser = WorkSheetParser
parser.source = BytesIO(src)
for _ in parser.parse():
pass
el = fromstring(src)
parser.parse_row_breaks(el)
assert parser.page_breaks == [expected_pagebreak]
def test_col_break(self, WorkSheetParser):
src = b"""
<colBreaks count="1" manualBreakCount="1" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<brk id="15" man="1" max="16383" min="0"/>
</colBreaks>
"""
expected_pagebreak = ColBreak()
expected_pagebreak.append(Break(id=15))
parser = WorkSheetParser
el = fromstring(src)
parser.parse_col_breaks(el)
assert parser.page_breaks == [expected_pagebreak]
......
......@@ -56,7 +56,7 @@ from .views import (
from .cell_range import MultiCellRange, CellRange
from .merge import MergedCellRange
from .properties import WorksheetProperties
from .pagebreak import PageBreak
from .pagebreak import RowBreak, ColBreak
from .scenario import ScenarioList
......@@ -106,7 +106,9 @@ class Worksheet(_WorkbookChild):
default_factory=self._add_row)
self.column_dimensions = DimensionHolder(worksheet=self,
default_factory=self._add_column)
self.page_breaks = [PageBreak()]
self.row_breaks = RowBreak()
self.col_breaks = ColBreak()
self.page_breaks = [self.row_breaks, self.col_breaks]
self._cells = {}
self._charts = []
self._images = []
......
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