fix layout recovery error: list index out of range (#12541)

pull/12565/head
Wang Xin 2024-05-31 11:23:02 +08:00 committed by GitHub
parent 49a388db0a
commit 56fc05e604
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -249,6 +249,9 @@ class HtmlToDocx(HTMLParser):
table = doc.add_table(len(rows), cols_len)
table.style = doc.styles["Table Grid"]
num_rows = len(table.rows)
num_cols = len(table.columns)
cell_row = 0
for index, row in enumerate(rows):
cols = get_table_columns(row)
@ -261,6 +264,9 @@ class HtmlToDocx(HTMLParser):
if col.name == "th":
cell_html = "<b>%s</b>" % cell_html
if cell_row >= num_rows or cell_col >= num_cols:
continue
docx_cell = table.cell(cell_row, cell_col)
while docx_cell.text != "": # Skip the merged cell