Re: [sc-dev] How to access cell values in a cell range in Calc add-ins?

2010-10-18 Thread Niklas Nebel

On 10/18/10 07:51, Pivithuru Wijegunawardana wrote:

You can use com.sun.star.sheet.XCellRangeAddressable interface and
CellRangeAddress.

com.sun.star.sheet.XCellRangeAddressable xRangeAddr =
(com.sun.star.sheet.XCellRangeAddressable)
UnoRuntime.queryInterface(com.sun.star.sheet.XCellRangeAddressable.class,
xCellRange);

CellRangeAddress aRangeAddress = xRangeAddr.getRangeAddress();

 From aRangeAddress you can get details about range start column,start row
  and range end column,end row. Then you can get the no of columns and rows
you have in the range

int noOfColums = aRangeAddress.EndColumn - aRangeAddress.StartColumn + 1;
int noOfRows = aRangeAddress.EndRow - aRangeAddress.StartRow + 1;

Then traverse through the range using this and you can get all the cells
inside the given range.

for (int i = 0; i<  noOfColums; i++) {

 for (int j = 0; j<  noOfRows; j++) {

 XCell cell = xCellRange.getCellByPosition(i, j);

 }


Or if the parameter has a type like "sequence< sequence< double > >" in 
IDL, which is "double[][]" in Java, you can just use "length" to access 
the array's length.


Niklas

-
To unsubscribe, e-mail: dev-unsubscr...@sc.openoffice.org
For additional commands, e-mail: dev-h...@sc.openoffice.org



Re: [sc-dev] How to access cell values in a cell range in Calc add-ins?

2010-10-17 Thread Pivithuru Wijegunawardana
Hi Nadee,

You can use com.sun.star.sheet.XCellRangeAddressable interface and
CellRangeAddress.

com.sun.star.sheet.XCellRangeAddressable xRangeAddr =
(com.sun.star.sheet.XCellRangeAddressable)
UnoRuntime.queryInterface(com.sun.star.sheet.XCellRangeAddressable.class,
xCellRange);

CellRangeAddress aRangeAddress = xRangeAddr.getRangeAddress();

>From aRangeAddress you can get details about range start column,start row
 and range end column,end row. Then you can get the no of columns and rows
you have in the range

int noOfColums = aRangeAddress.EndColumn - aRangeAddress.StartColumn + 1;
int noOfRows = aRangeAddress.EndRow - aRangeAddress.StartRow + 1;

Then traverse through the range using this and you can get all the cells
inside the given range.

for (int i = 0; i < noOfColums; i++) {

for (int j = 0; j < noOfRows; j++) {

XCell cell = xCellRange.getCellByPosition(i, j);

}

Hope this might help you


-- 
Best regards,
Pivithuru Wijegunawardana
University of Moratuwa
Sri Lanka



On Mon, Oct 18, 2010 at 12:58 AM, Nadee Hwg  wrote:

> Hi, i have succeeded in adding a function to Calc and reading the input
> figures on a Calc spreadsheet. I'm using the .impl.java file
> generated and changing its return statement so as to give the result of my
> function.
>
> But I can only access a pre-defined number of cells only. i.e. the size of
> the array i define in the java code. How can I access a dynamically
> determined cell range and use its values to do a computation?? [image:
> Rolling Eyes]
> eg: when the user inputs the cell values as
> 2 4 7
> 1 7 3
> 4 3 9
> each value in one cell, and when I program to take a 3*3 array(2-D array),
> computation succeeds(obvious) But I need to extend the code to be able to
> access any sized cell range.
>
> I've tried out the method of creating the for loop as
> for(int i=0; ; i++){
> for(int j=0; ; j++){
> ...
> }
> }
> but it even doesn't work
>
> Great help if one can give me a hint.
> Thanx in advance
>
> --
> ~SeekerN~
>


[sc-dev] How to access cell values in a cell range in Calc add-ins?

2010-10-17 Thread Nadee Hwg
Hi, i have succeeded in adding a function to Calc and reading the input
figures on a Calc spreadsheet. I'm using the .impl.java file
generated and changing its return statement so as to give the result of my
function.

But I can only access a pre-defined number of cells only. i.e. the size of
the array i define in the java code. How can I access a dynamically
determined cell range and use its values to do a computation?? [image:
Rolling Eyes]
eg: when the user inputs the cell values as
2 4 7
1 7 3
4 3 9
each value in one cell, and when I program to take a 3*3 array(2-D array),
computation succeeds(obvious) But I need to extend the code to be able to
access any sized cell range.

I've tried out the method of creating the for loop as
for(int i=0; ; i++){
for(int j=0; ; j++){
...
}
}
but it even doesn't work

Great help if one can give me a hint.
Thanx in advance

-- 
~SeekerN~