(Regard the amendment by editing below!)
There is no EVALUATEFORMULA()
function in Calc, and in many cases like yours the formula contains references (partly?) relative, which only can be evaluated if the base cell is known.
If you are sure to never again need a recalculation, you can try it this way:
targetCell = ThisComponent.Sheets(0).getCellByPosition(theCol, theRow)
targetCell.setFormula(("=...(whatever you have)...") REM Be careful with references!!
Select Case targetCell.FormulaResultType2
REM Overwriting the properties .Value or .String will dispose the formula again.
Case 1 REM Number type Double
targetCell.Value = targetCell.Value
Case 2 REM text type String
targetCell.String = targetCell.String
End Select
By the way “more than a thousand formulas” will rarely be a problem if not very complicated and inefficient.
Also: There may be good reasons to work with the range properties .DataArray
, .FormulaArray
, and …
Edit 2021-03-15 about 21:50 UTC
As reported by the questioner the above code didn’t work correctly though it’s correct. (A wee little bug.)
The following replacement is tested now (V 7.0.4.2) and worked as expected:
targetCell = ThisComponent.Sheets(0).getCellByPosition(theCol, theRow)
targetCell.setFormula(("=...(whatever you have)...") REM Be careful with references!!
Select Case targetCell.FormulaResultType2
REM Overwriting the properties .Value or .String will dispose the formula again.
Case 1 REM Number type Double
v = targetCell.Value
targetCell.Value = v
Case 2 REM text type String
s = targetCell.String
targetCell.String = s
End Select