XLLoop (Excel 2010) - 集成一个 java 函数,该函数 returns 一个 array/list 值
XLLoop (Excel 2010) - Integrating a java function that returns an array/list of values
我已经开始研究 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 那个 return 一个值中。 E.g.Math.random(), Math.pow(2, 4.45) 这两个 return 单双。
但是,我无法集成任何 return 和 array/list 值的函数。例如,在上面我们注册了 Maths class(一个 XLLoop class)用于 Excel。此 class 包含一个静态方法
public static double[] normalDist(int var0)
方法 return 是一个长度为 var0 的数组,但是当我在 Excel 中调用它时,只有一个单元格填充了一个值,我预计 var0 单元格已填充。这对我来说似乎是一个相当基本的功能,所以我很确定我一定是在做一些愚蠢的事情。
如果有人可以提供帮助,我们将不胜感激。
我还应该提到,我发现 similar SO question , linked from a R related SO questions feed. Unfortunately the original SO question 已被发布者从 SO 中删除...
您需要在excel中输入调用returns数组作为矩阵函数的方法的函数:select应接收返回数据的单元格,输入函数并按 ctrl-shift-enter。
如果范围 selected 太小,则只显示适合该范围的值。
我已经开始研究 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 那个 return 一个值中。 E.g.Math.random(), Math.pow(2, 4.45) 这两个 return 单双。
但是,我无法集成任何 return 和 array/list 值的函数。例如,在上面我们注册了 Maths class(一个 XLLoop class)用于 Excel。此 class 包含一个静态方法
public static double[] normalDist(int var0)
方法 return 是一个长度为 var0 的数组,但是当我在 Excel 中调用它时,只有一个单元格填充了一个值,我预计 var0 单元格已填充。这对我来说似乎是一个相当基本的功能,所以我很确定我一定是在做一些愚蠢的事情。
如果有人可以提供帮助,我们将不胜感激。
我还应该提到,我发现 similar SO question , linked from a R related SO questions feed. Unfortunately the original SO question 已被发布者从 SO 中删除...
您需要在excel中输入调用returns数组作为矩阵函数的方法的函数:select应接收返回数据的单元格,输入函数并按 ctrl-shift-enter。 如果范围 selected 太小,则只显示适合该范围的值。