Skip to content

Commit

Permalink
Better exception handling in tables (#37)
Browse files Browse the repository at this point in the history
* Fix crash on unsupported cell interfaces

* Better exception handling in tables
  • Loading branch information
Nathn authored May 31, 2024
1 parent bb83251 commit 4e1b211
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lotemplate/Statement/TableStatement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from com.sun.star.lang import XComponent
from com.sun.star.sheet import XCellRangeData
from com.sun.star.uno import RuntimeException
from typing import Union
import lotemplate.errors as errors
import regex
Expand Down Expand Up @@ -47,15 +47,18 @@ def scan_cell(cell) -> None:
tab_vars = {}
list_tab_vars = []
for i in range(doc.getTextTables().getCount()):
table = doc.getTextTables().getByIndex(i)
if not isinstance(table, XCellRangeData):
try:
table_data = doc.getTextTables().getByIndex(i).getDataArray()
t_name = doc.getTextTables().getByIndex(i).getName()
nb_rows = len(table_data)
for row_i, row in enumerate(table_data):
for column in row:
scan_cell(column)
except errors.TemplateError as e:
raise e
continue
except RuntimeException as e:
continue
table_data = table.getDataArray()
t_name = doc.getTextTables().getByIndex(i).getName()
nb_rows = len(table_data)
for row_i, row in enumerate(table_data):
for column in row:
scan_cell(column)

return list_tab_vars if get_list else tab_vars

Expand Down

0 comments on commit 4e1b211

Please sign in to comment.