[FIX] report_xlsx_helper: force Libreoffice to recompute formulas
As per https://xlsxwriter.readthedocs.io/faq.html: Q. Why do my formulas show a zero result in some, non-Excel applications? A. [...] Or, you can set a blank result in the formula, which will also force recalculation.pull/482/head
parent
f95a30c90d
commit
2d5945dbed
|
@ -636,6 +636,7 @@ class ReportXlsxAbstract(models.AbstractModel):
|
||||||
if isinstance(cell_format, CodeType):
|
if isinstance(cell_format, CodeType):
|
||||||
cell_format = self._eval(cell_format, render_space)
|
cell_format = self._eval(cell_format, render_space)
|
||||||
args_data.append(cell_format)
|
args_data.append(cell_format)
|
||||||
|
self._apply_formula_quirk(args_data, cell_type, cell_format)
|
||||||
if colspan > 1:
|
if colspan > 1:
|
||||||
args_pos += [row_pos, pos + colspan - 1]
|
args_pos += [row_pos, pos + colspan - 1]
|
||||||
args = args_pos + args_data
|
args = args_pos + args_data
|
||||||
|
@ -648,6 +649,15 @@ class ReportXlsxAbstract(models.AbstractModel):
|
||||||
|
|
||||||
return row_pos + 1
|
return row_pos + 1
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _apply_formula_quirk(args_data, cell_type, cell_format):
|
||||||
|
""" Insert empty value to force LibreOffice to recompute the value """
|
||||||
|
if cell_type == "formula":
|
||||||
|
if not cell_format:
|
||||||
|
# Insert positional argument for missing format
|
||||||
|
args_data.append(None)
|
||||||
|
args_data.append("")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _render(code):
|
def _render(code):
|
||||||
return compile(code, "<string>", "eval")
|
return compile(code, "<string>", "eval")
|
||||||
|
|
Loading…
Reference in New Issue