Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion pyexcel_xlsxr/messy_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ def __repr__(self):
return str(self.value)


def column_to_number(column):
column = re.sub("[^A-Z]", "", column)
cl = len(column) - 1
return sum(
[(ord(c.upper()) - 64) + (26 * (cl - i)) for i, c in enumerate(column)]
)


def parse_row(row_xml_string, book):
if b"x14ac" in row_xml_string:
row_xml_string = row_xml_string.replace(
Expand All @@ -191,11 +199,20 @@ def parse_row(row_xml_string, book):
cells = []
cell = Cell()

last_column_number = None
for action, element in etree.iterparse(partial):

if element.tag in ["v", "t"]:
cell.value = element.text
elif element.tag in ["c"]:
ref = element.attrib.get("r")
if ref:
column_number = column_to_number(ref)
if last_column_number is not None:
padding = column_number - last_column_number - 1
if padding > 0:
cells += [Cell() for _ in range(padding)]
last_column_number = column_number

local_type = element.attrib.get("t")
cell.column_type = local_type
style_int = element.attrib.get("s")
Expand Down