reformatted the code

Signed-off-by: Peter Staar <taa@zurich.ibm.com>
This commit is contained in:
Peter Staar 2024-11-19 11:22:29 +01:00
parent f837105a09
commit d23aea981d

View File

@ -177,7 +177,7 @@ class MsExcelDocumentBackend(DeclarativeDocumentBackend):
"""
Find all compact rectangular data tables in a sheet.
"""
#_log.info("find_data_tables")
# _log.info("find_data_tables")
tables = [] # List to store found tables
visited: set[Tuple[int, int]] = set() # Track already visited cells
@ -230,11 +230,15 @@ class MsExcelDocumentBackend(DeclarativeDocumentBackend):
row_span = 1
col_span = 1
#_log.info(sheet.merged_cells.ranges)
# _log.info(sheet.merged_cells.ranges)
for merged_range in sheet.merged_cells.ranges:
if merged_range.min_row<=ri+1 and ri+1<=merged_range.max_row and \
merged_range.min_col<=rj+1 and rj+1<=merged_range.max_col:
if (
merged_range.min_row <= ri + 1
and ri + 1 <= merged_range.max_row
and merged_range.min_col <= rj + 1
and rj + 1 <= merged_range.max_col
):
row_span = merged_range.max_row - merged_range.min_row + 1
col_span = merged_range.max_col - merged_range.min_col + 1
@ -243,8 +247,8 @@ class MsExcelDocumentBackend(DeclarativeDocumentBackend):
if (ri, rj) not in visited_cells:
data.append(
ExcelCell(
row = ri - start_row,
col = rj - start_col,
row=ri - start_row,
col=rj - start_col,
text=str(cell.value),
row_span=row_span,
col_span=col_span,
@ -266,7 +270,7 @@ class MsExcelDocumentBackend(DeclarativeDocumentBackend):
visited_cells,
)
def _find_table_bottom(self, sheet: Worksheet, start_row:int, start_col:int):
def _find_table_bottom(self, sheet: Worksheet, start_row: int, start_col: int):
"""Function to find the bottom boundary of the table"""
max_row = start_row
@ -286,13 +290,13 @@ class MsExcelDocumentBackend(DeclarativeDocumentBackend):
# Expand max_row to include the merged range if applicable
if merged_range:
max_row = max(max_row, merged_range.max_row-1)
max_row = max(max_row, merged_range.max_row - 1)
else:
max_row += 1
return max_row
def _find_table_right(self, sheet: Worksheet, start_row:int, start_col:int):
def _find_table_right(self, sheet: Worksheet, start_row: int, start_col: int):
"""Function to find the right boundary of the table"""
max_col = start_col
@ -312,13 +316,12 @@ class MsExcelDocumentBackend(DeclarativeDocumentBackend):
# Expand max_col to include the merged range if applicable
if merged_range:
max_col = max(max_col, merged_range.max_col-1)
max_col = max(max_col, merged_range.max_col - 1)
else:
max_col += 1
return max_col
def _find_images_in_sheet(
self, doc: DoclingDocument, sheet: Worksheet
) -> DoclingDocument: