Commit bb42fcbb authored by patrik.simons@neotide.fi's avatar patrik.simons@neotide.fi
Browse files

Handle missing r attributes in rows and cells.

Use the current row number when the r attribute for a row is missing.
Reset the current column when parsing a new row so cells missing the r
attribute get the correct column.

--HG--
branch : issue-1321
parent a2ee53b78166
......@@ -85,7 +85,7 @@ class WorkSheetParser(object):
def __init__(self, src, shared_strings, data_only=False,
epoch=WINDOWS_EPOCH, date_formats=set()):
self.min_row = self.min_col = self.max_row = self.max_column = None
self.min_row = self.min_col = None
self.epoch = epoch
self.source = src
self.shared_strings = shared_strings
......@@ -261,11 +261,12 @@ class WorkSheetParser(object):
self.max_row = int(attrs['r'])
else:
self.max_row += 1
self.max_column = 0
keys = {k for k in attrs if not k.startswith('{')}
if keys != {'r', 'spans'} and keys != {'r'}:
# don't create dimension objects unless they have relevant information
self.row_dimensions[attrs['r']] = attrs
self.row_dimensions[str(self.max_row)] = attrs
cells = [self.parse_cell(el) for el in row]
return self.max_row, cells
......
......@@ -470,6 +470,31 @@ class TestWorksheetParser:
assert parser.max_column == 5
def test_row_and_cell_without_coordinates(self, WorkSheetParser):
parser = WorkSheetParser
src = """
<row>
<c t="s">
<v>2</v>
</c>
<c t="s">
<v>4</v>
</c>
<c t="s">
<v>3</v>
</c>
</row>
"""
element = fromstring(src)
parser.shared_strings = ["Whatever"] * 7
parser.parse_row(element)
parser.parse_row(element)
assert parser.max_row == 2
assert parser.max_column == 3
def test_external_hyperlinks(self, WorkSheetParser):
src = b"""
<hyperlinks xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
......
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