XLLoop(Excel 2010) – 集成一个返回数组/值列表的java函数

我已经开始研究XLLoop了,因为我需要一种从java系统中获取数据到Excel(2010版)的方法。

我已经按照网站首页上的Java SimpleServer示例进行了操作:

package org.boris.xlloop.util; import org.boris.xlloop.FunctionServer; import org.boris.xlloop.handler.*; import org.boris.xlloop.reflect.*; public class ServerExample { public static void main(String[] args) throws Exception { // Create function server on the default port FunctionServer fs = new FunctionServer(); // Create a reflection function handler and add the Math methods ReflectFunctionHandler rfh = new ReflectFunctionHandler(); rfh.addMethods("Math.", Math.class); rfh.addMethods("Math.", Maths.class); rfh.addMethods("CSV.", CSV.class); rfh.addMethods("Reflect.", Reflect.class); // Create a function information handler to register our functions FunctionInformationHandler firh = new FunctionInformationHandler(); firh.add(rfh.getFunctions()); // Set the handlers CompositeFunctionHandler cfh = new CompositeFunctionHandler(); cfh.add(rfh); cfh.add(firh); fs.setFunctionHandler(new DebugFunctionHandler(cfh)); // Run the engine System.out.println("Listening on port " + fs.getPort() + "..."); fs.run(); } } 

并已成功地将简单的静态Java方法集成到Excel中,返回一个值。 EgMath.random(),Math.pow(2,4.45)这两个返回一个单一的双。

但是,我一直无法集成任何返回数组/值列表的函数。 例如,在上面我们已经注册了在Excel中使用的Maths类(一个XLLoop类)。 这个类包含一个静态方法

 public static double[] normalDist(int var0) 

该方法返回一个长度var0的数组,但是当我在Excel中调用这个只有一个单元格填充一个值时,我会预期var0单元格已被填充。 这对我来说似乎是一个相当基本的特点,所以我很确定我必须做一些愚蠢的事情。

如果有谁可以帮助,这将不胜感激。

我还应该提到,我发现了一个类似的SO问题 ,从R相关的SO问题提要链接。 不幸的是原来的SO问题已经从海报中删除了…

你需要在excel中input函数调用返回一个数组作为matrix函数的方法:select要接收返回数据的单元格,input函数并按下ctrl-shift-enter。 如果select的范围太小,则只显示范围内的值。