diff --git a/docling_core/types/doc/document.py b/docling_core/types/doc/document.py index 4c05bfba..aac40319 100644 --- a/docling_core/types/doc/document.py +++ b/docling_core/types/doc/document.py @@ -352,6 +352,7 @@ def grid( ] # Overwrite cells in table data for which there is actual cell content. + count = 1 for cell in self.table_cells: for i in range( min(cell.start_row_offset_idx, self.num_rows), @@ -361,7 +362,11 @@ def grid( min(cell.start_col_offset_idx, self.num_cols), min(cell.end_col_offset_idx, self.num_cols), ): - table_data[i][j] = cell + if count <= len(self.table_cells): + table_data[i][j] = cell + count += 1 + else: + break return table_data