Bug 148646 - Analysis functions taking XPropertySet argument need explicit documentation
Summary: Analysis functions taking XPropertySet argument need explicit documentation
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Documentation (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL: https://ask.libreoffice.org/t/need-fo...
Whiteboard: QA:needsComment
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-18 09:29 UTC by Mike Kaganski
Modified: 2023-03-16 10:00 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2022-04-18 09:29:29 UTC
Add-in functions and calling them from macros are documented at [1]. Naturally, they are documented as implementation of respective spreadsheet functions.

But for some (most) of those, the implementation [2] takes more arguments than the spreadsheet function takes: the internal code also passes an '[in] com::sun::star::beans::XPropertySet xOptions' argument used to get util::XNumberFormatsSupplier, used internally to convert between strings and numbers.

The argument may be simply an empty reference (in which case, a default locale-independent conversion would be used), so e.g. Basic macros may pass 'Nothing' constant as the value; or they may pass objects implementing the XNumberFormatsSupplier interface [3] - like current document.

All this is not obvious for the reader of the current documentation, so it would be nice to amend it with this information (which would require to list arguments for each such function).

[1] https://help.libreoffice.org/7.3/en-US/text/sbasic/shared/calc_functions.html?&DbPAR=CALC
[2] https://opengrok.libreoffice.org/xref/core/scaddins/idl/com/sun/star/sheet/addin/XAnalysis.idl?r=cc7ff0c1
[3] https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1util_1_1XNumberFormatsSupplier.html
Comment 1 Mike Kaganski 2022-04-18 09:44:16 UTC
And also there should be documented the alternative (maybe preferred) way of calling those functions: using the same 'com.sun.star.sheet.FunctionAccess' service as suggested for all other functions, *but* stressing that one needs to use the full name of the function, like 'com.sun.star.sheet.addin.Analysis.getDec2Hex', there. That way, all the extra complexity is avoided.
Comment 2 Mike Kaganski 2023-03-16 10:00:28 UTC
(In reply to Mike Kaganski from comment #0)
> The argument may be simply an empty reference (in which case, a default
> locale-independent conversion would be used), so e.g. Basic macros may pass
> 'Nothing' constant as the value; or they may pass objects implementing the
> XNumberFormatsSupplier interface [3] - like current document.

Note that *some* functions really require something in this parameter. E.g., as noted in [1], getWeeknum (and other functions taking dates) requires the passed *property set* contain "NullDate" property, usually set to the Basic's null date (unless user decides to pass a custom integer as the date), which can be done using code like

 oPropBag = CreateUnoService("com.sun.star.beans.PropertyBag")
 oPropBag.addProperty("NullDate", 0, CDateToUnoDate(Empty))
 oService = CreateUnoService("com.sun.star.sheet.addin.Analysis")
 WkNum = oService.getWeeknum(oPropBag, CDate("2023-03-02"), 1)

(In reply to Mike Kaganski from comment #1)
> And also there should be documented the alternative (maybe preferred) way of
> calling those functions: using the same 'com.sun.star.sheet.FunctionAccess'
> service as suggested for all other functions, *but* stressing that one needs
> to use the full name of the function, like
> 'com.sun.star.sheet.addin.Analysis.getDec2Hex', there. That way, all the
> extra complexity is avoided.

Note that erAck has implemented simpler way to call these in bug 150203 (since 7.4.1). Now these can be called simply by their spreadsheet function name, as other "normal" functions.

[1] https://ask.libreoffice.org/t/cant-get-the-add-in-weeknum-function-to-work-in-macro/89294/4