Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决导出表格标注时遇到的通用问题 #78

Merged
merged 2 commits into from
Sep 13, 2024
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
15 changes: 9 additions & 6 deletions libs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 = "<html><body><table>{}</table></body></html>".format(html_code)
return html_code

Expand Down