Bug 130661 - MACRO setformula does not appear to work with array formula
Summary: MACRO setformula does not appear to work with array formula
Status: RESOLVED WORKSFORME
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
5.4.6.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-14 14:17 UTC by christophe.alviset
Modified: 2020-02-14 20:24 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 christophe.alviset 2020-02-14 14:17:28 UTC
Description:
Hi
I am using array formulas. For some reason, while using macros or sorting or something else, the array formulas go away and I am left with simple formulas (ie SUM(...) instead of {SUM(...)}

I want to write a macro to reset these cells to array formulas, but setformula does not seem to work with an array formula. It sets a string.

Thank you for looking

Christophe


Steps to Reproduce:
The data
Cells A1 contain 1, A2, 4, B1, 0, B2, 1.
Array formula {=SUM((A1:A2)*(B1:B2))} yields 4 while =SUM((A1:A2)*(B1:B2)) yields 0. This is fine

The macro instructions
oBug.getCellByPosition(2,0).setFormula("=SUM((A1:A2)*(B1:B2))")
has a cell type 3 (=FORMULA)
Whereas
oBug.getCellByPosition(2,0).setFormula("{=SUM((A1:A2)*(B1:B2))}")
has a cell type 2 (=STRING)

I did not find a way to set the cell type to FORMULA.



Actual Results:
cell type 2 (=STRING)

Expected Results:
cell type 3 (=FORMULA)


Reproducible: Always


User Profile Reset: No



Additional Info:
I am using the French Libreoffice version.
Comment 1 Oliver Brinzing 2020-02-14 18:04:47 UTC
(In reply to christophe.alviset from comment #0)
> I am using array formulas. For some reason, while using macros or sorting or
> something else, the array formulas go away and I am left with simple
> formulas (ie SUM(...) instead of {SUM(...)}
> 
> I want to write a macro to reset these cells to array formulas, but
> setformula does not seem to work with an array formula. It sets a string.

Please try with setArrayFormula(), e.g:

ThisComponent.getSheets().getByIndex(0).getCellByPosition(0,2).setArrayFormula("=SUM((A1:A2)*(B1:B2))")
Comment 2 christophe.alviset 2020-02-14 20:24:08 UTC
Thanks a lot