reports: BaseODS puts each line of strings in a P tag.

This seems to be the most straightforward way to get Calc to automatically
determine a nice row height for multi-line string cells. This has become a
lot more noticeable now that query-report supports putting postal addresses
in cells.
This commit is contained in:
Brett Smith 2021-03-15 11:59:12 -04:00
parent fff211386f
commit 6703d1af87
2 changed files with 13 additions and 4 deletions

View file

@ -1436,9 +1436,15 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta):
return self.multilink_cell(self._meta_link_pairs(links), **attrs) return self.multilink_cell(self._meta_link_pairs(links), **attrs)
def multiline_cell(self, lines: Iterable[Any], **attrs: Any) -> odf.table.TableCell: def multiline_cell(self, lines: Iterable[Any], **attrs: Any) -> odf.table.TableCell:
item_lines = [str(item).splitlines() for item in lines if item is not None]
if any(len(seq) > 1 for seq in item_lines):
for seq in item_lines:
seq.append('')
seq.pop()
cell = odf.table.TableCell(valuetype='string', **attrs) cell = odf.table.TableCell(valuetype='string', **attrs)
for line in lines: for seq in item_lines:
cell.addElement(odf.text.P(text=str(line))) for line in seq:
cell.addElement(odf.text.P(text=line))
return cell return cell
def multilink_cell(self, links: Iterable[LinkType], **attrs: Any) -> odf.table.TableCell: def multilink_cell(self, links: Iterable[LinkType], **attrs: Any) -> odf.table.TableCell:
@ -1457,7 +1463,8 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta):
def string_cell(self, text: str, **attrs: Any) -> odf.table.TableCell: def string_cell(self, text: str, **attrs: Any) -> odf.table.TableCell:
cell = odf.table.TableCell(valuetype='string', **attrs) cell = odf.table.TableCell(valuetype='string', **attrs)
cell.addElement(odf.text.P(text=text)) for line in text.splitlines():
cell.addElement(odf.text.P(text=line))
return cell return cell
def write_row(self, row: RT) -> None: def write_row(self, row: RT) -> None:

View file

@ -193,7 +193,9 @@ def check_ods_sheet(sheet, account_balances, *, full):
cells = iter(testutil.ODSCell.from_row(row)) cells = iter(testutil.ODSCell.from_row(row))
try: try:
fund = next(cells).firstChild.text fund = next(cells).firstChild.text
except (AttributeError, StopIteration): except AttributeError:
fund = ''
except StopIteration:
continue continue
try: try:
balances = account_bals.pop(fund) balances = account_bals.pop(fund)