reports: Add BaseODS.row_count() method.

This commit is contained in:
Brett Smith 2021-01-29 14:26:54 -05:00
parent 250b14954f
commit ca38e45178
2 changed files with 15 additions and 0 deletions

View file

@ -1342,6 +1342,12 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta):
self.sheet.addElement(row)
return row
def row_count(self, sheet: Optional[odf.table.Table]=None) -> int:
if sheet is None:
sheet = self.sheet
TableRow = odf.table.TableRow
return sum(1 for cell in sheet.childNodes if cell.isInstanceOf(TableRow))
def balance_cell(self, balance: Balance, **attrs: Any) -> odf.table.TableCell:
balance = balance.clean_copy() or balance
balance_currency_count = len(balance)

View file

@ -526,6 +526,15 @@ def test_ods_writer_add_row_empty(ods_writer):
assert row.firstChild is None
assert row.getAttribute('stylename') == 'blank'
@pytest.mark.parametrize('col_count', range(3))
def test_ods_writer_row_count(ods_writer, col_count):
for _ in range(col_count):
ods_writer.sheet.addElement(odf.table.TableColumn())
assert ods_writer.row_count() == 0
for expected in range(1, 4):
ods_writer.sheet.addElement(odf.table.TableRow())
assert ods_writer.row_count() == expected
def test_ods_writer_balance_cell_empty(ods_writer):
balance = core.Balance()
cell = ods_writer.balance_cell(balance)