OpenOffice Automation Delphi how use a callfunction – Education Career Blog

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

,

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);

Leave a Comment