1 Replies Last post: May 25, 2009 3:41 PM by Serge Piletsky  
Michel Page   2 posts since
May 21, 2009
Currently Being Moderated

May 25, 2009 11:08 AM

Array formula in JExcel

I need to generate an Excel file containing an array formula defined on a range of cells. What is the proper call to JExcel API to perform this operation ?

For instance, I want to generate one array formula for generating range C1:C4 in the following sheet :

   A     B        C

1| 2     4

2| 5     1

3| 3     4

4| 6     2

 

with C1:C4 computed as A1:A4+B1:B4 (i.e. 6;6;7;8). Beware, I don't dont to fill C1 with formula "=A1+B1", C2 with formula "=A2+B2" and so on. I want to generate one array formula {=A1:A4+B1:B4} on C1:C4.

Serge Piletsky TeamDev Ltd. 996 posts since
Apr 24, 2006
Currently Being Moderated
1. May 25, 2009 3:41 PM in response to: Michel Page
Re: Array formula in JExcel

Hi Michel,

 

This is also possible to achieve using JExcel and again using Range's peer object. The following example demonstrates it:

Worksheet worksheet = ...;
 
long[][] data = {{2, 4}, {5, 1}, {3, 4}, {6, 2}};
worksheet.fillWithArray("A1:B4", data);
 
final com.jniwrapper.win32.jexcel.Range range = worksheet.getRange("C1:C4");
range.getOleMessageLoop().doInvokeAndWait(new Runnable() {
    public void run() {
        range.getPeer().setFormulaArray(new Variant("=A1:A4+B1:B4"));
    }
});

In the next version of JExcel we will add the appropriate method to the com.jniwrapper.win32.jexcel.Range class.

 

Please let me know if you have any further questions.

 

-Serge

More Like This

  • Retrieving data ...