diff --git a/libs/utils.py b/libs/utils.py index 4a2c23e..80c9c08 100644 --- a/libs/utils.py +++ b/libs/utils.py @@ -205,14 +205,16 @@ def expand_list(merged, html_list): Fill blanks according to merged cells """ sr, er, sc, ec = merged - for i in range(sr, er): - for j in range(sc, ec): + # Fill the range of merged cells with None + for i in range(sr, er + 1): + for j in range(sc, ec + 1): html_list[i][j] = None + # Add the colspan and rowspan attributes only if necessary html_list[sr][sc] = "" - if ec - sc > 1: - html_list[sr][sc] += " colspan={}".format(ec - sc) - if er - sr > 1: - html_list[sr][sc] += " rowspan={}".format(er - sr) + if ec - sc > 0: # Only add colspan if the column span is more than 1 + html_list[sr][sc] += " colspan={}".format(ec - sc + 1) + if er - sr > 0: # Only add rowspan if the row span is more than 1 + html_list[sr][sc] += " rowspan={}".format(er - sr + 1) return html_list @@ -257,6 +259,7 @@ def rebuild_html_from_ppstructure_label(label_info): cell = "".join(cell) html_code.insert(i + 1, cell) html_code = "".join(html_code) + html_code = re.sub(r'(colspan|rowspan)="(\d+)"', r"\1=\2", html_code) html_code = "{}
".format(html_code) return html_code