Skip to content

Commit

Permalink
Merge pull request #9 from mtskelton/dev
Browse files Browse the repository at this point in the history
Potential fix for incorrect reading of data with empty cells when used with pyexcel
  • Loading branch information
chfw authored Nov 11, 2024
2 parents 80bd1e4 + 057cea8 commit be0613d
Showing 1 changed file with 18 additions and 1 deletion.
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

0 comments on commit be0613d

Please sign in to comment.