views:

71

answers:

1

Hello, please help me with the following: I want to determine the maximum value in an open office calc column using the OOoTools.pas interface. This as fas as I come:

Procedure FindMaximum(oMySheet : Variant);
Var
            oFuncService : Variant;
Begin
  oFuncService := CreateUnoService('com.sun.star.sheet.FunctionAccess');
  ShowMessage(oFuncService.callFunction('MAX', VarArrayOf([10,20,50])));
End;

This works

Of course I want to fill in the values of a column like:

ShowMessage(oFuncService.callFunction('MAX', VarArrayOf([oMySheet.getCellRangeByName('K8:K10')])));

I get the message "com.star.lang.IllegalArgumentException:." why? Thanks

A: 

Here I am again.

Is it the callFunction method that gives this error or the getCellRangeByName method?

procedure FindMaximum(oMySheet : Variant);
var
  oFuncService : Variant;
  oCellRange: Variant;
  oResult: Variant;
begin
  oFuncService := CreateUnoService('com.sun.star.sheet.FunctionAccess');

  //error here?
  oCellRange := oMySheet.getCellRangeByName('K8:K10');

  //or error here?
  oResult := oFuncService.callFunction('MAX', VarArrayOf([oCellRange]));

  ShowMessage(oResult);
end;

I have to say that I find the documentation a bit unclear.

When you have the error on the callFunction method in my above sample, try this:

//CellRange not wrapped in a VariantArray
oResult := oFuncService.callFunction('MAX', oCellRange);
The_Fox
The error occurs on oResult := oFuncService.callFunction('MAX', VarArrayOf([oCellRange]));
addelichtman
Hello The_Fox, then I get a "Type Mismatch" error
addelichtman
@addelichtman: Is there maybe an invalid value in your K8:K10 range? Text instead of numeric value?
The_Fox
Absolutely shure the column only contains integers. Does the line oMySheet.getCellRangeByName('K8:K70'); return the contents of the column?
addelichtman
I'm now looking to the GetDataArray method...
addelichtman
@addelichtman: Maybe it is a bug in the Automation bridge. When I do the same in Calc's macro editor it works. But when I try this in Delphi it just refuses to work. Even when I work with ValueObjects (Bridge_GetValueObject) to specify the exact types I get errors.
The_Fox
Thank you very much for your time I'll do the function by iterating through the cell values (will be much slower I expect) greetings Addelichtman
addelichtman