How to get the results of a formula for text based formulas?
I am using the following function to get the cell value.
def get_val(cell: XCell) -> Any:
t = cell.getType()
if t == CellContentType.EMPTY:
return None
if t == CellContentType.VALUE:
return convert_to_float(cell.getValue())
if t in (CellContentType.TEXT, CellContentType.FORMULA):
# https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1sheet_1_1FormulaResult.html
ft = cell.FormulaResultType2
if ft == 1: # VALUE
return cell.getValue()
if ft == 2: # STRING
return cell.getFormula()
if ft == 4: # ERROR
return f"(Error: {cell.getError()})"
return None
Test SUM
A1
value 10
B1
value 20
C1
value =SUM(A1:B1)
get_val()
for C1
returns 30
Test String
A2
value Hello
get_val()
for A2
returns Hello
Test Formula String
A3
value Hello
B3
value World
C3
value =CONCATENATE(A3,B3)
get_val()
for C1
returns (Error: 508)
How to Get Formula value?
Is there a way to get the actual formula results from a Calc cell when the result should be text?
How would I get the result of HelloWorld
from =CONCATENATE(A3,B3)
?