Dear LO community:
In BeanShell (Java), how could one retrieve the display content of an XCell object of arbitrary data type, as text in appearance identical to its cell display in Calc / “Function Wizard”?
For example, when XCell.getType() == CellContentType.FORMULA, for formulae of date type, of string type, etc., XCell.getValue() is not suited to build the display text shown by the cell display in Calc.
sheet.FormulaResult has been discussed concerning formulae results as a replacement for CellContentType, as shown below. I do not know how to translate its BASIC code to BeanShell (Java) code, due to uncertainty in the parameters for queryInterface().
A related LO feature “Function Wizard” works in interactive mode. “Function Wizard” (interactive) would become “Formula Evaluator” (automated) after suppressing the user dialog and user interaction, as discussed on superuser.com shown below. LO API does not publish the class which would behave as “Formula Evaluator” (automated) on the basis of “Function Wizard” (interactive). Similar to “Function Wizard”, “Formula Evaluator” needs to return an Object along with its display type info. (String, Date, etc.), in order to handle an XCell of arbitrary display type (output, format type, *NumberFormat*, semantics meaning of displayed data), and storage type (input, CellContentType.FORMULA).
The Apache POI project provides a class FormulaEvaluator to emulate the feature of the MS Excel VBA Application.Evaluate( formula ). There is difference between the object models of Apache POI and LO. An attempt to invoke the Apache POI FormulaEvaluator in LO Java code would not be a trivial effort.
Guidance or link to Java code illustration is appreciated. Thanks.
20161211 Macro: how to get a cell value set by a formula
Macro: how to get a cell value set by a formula
20191019 FormulaResultType return VALUE for cells with formula result #DIV/0! or #NAME?
http://bugs.documentfoundation.org/show_bug.cgi?id=70882
com.sun.star.table.XCell
http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1table_1_1XCell.html
double XCell.getValue()
(snip) … for a formula cell the result value of a formula is returned.
com.sun.star.sheet.FormulaResult
http://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1sheet_1_1FormulaResult.html
com.sun.star.sheet.SheetCell
http://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1sheet_1_1SheetCell.html#affda686bb18571c67c625c9adc1c85f9
table.CellContentType CellContentType → XCell.getType()
long sheet.SheetCell.FormulaResultType → table.CellContentType, XCell.getType()
long sheet.SheetCell.FormulaResultType2 → sheet.FormulaResult
20150711 LibreOffice Calc equivalent to Excel “Evaluate Formula” feature
http://www.superuser.com/questions/939363
LO / AOO, Function Wizard → select cell → ctrl + F2 → stepping through evaluation
Apache POI, Formula Evaluation
Formula Evaluation
FormulaEvaluator.evaluate( Cell cell )
FormulaEvaluator.evaluateFormulaCell( Cell cell )
FormulaEvaluator.evaluateInCell( Cell cell )
MS VBA Application.Evaluate( formula )
http://docs.microsoft.com/en-us/office/vba/api/excel.application.evaluate
MS Windows XP SP3, x32
LO 5.4.7.2, last version for XP
BeanShell 2.0.6
JRE 1.8.0.152 x32
JVM hotspot, not OpenJ9