java - 在 java 中使用 XLloop

标签 java excel

XLoop 是 java 的开源框架。例如,我们可以在Excel中使用java中的函数。下面是非常简单的用法示例:

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

我理解它并且通常程序正在运行。但如果我追求卓越,那是行不通的。 我尝试:

=FS("Math.random")
=Math.random()

但是我得到了 #NAME? 两次

所以我想我应该做点什么。你能一步步告诉我如何配置excel和java来做到这一点吗?我应该如何处理 xlloop-0.3.2(Microsoft Excel XLL 插件)文件?

最佳答案

我尝试运行代码并得到以下输出。

enter image description here

我所要做的就是启动 Excel 并添加 XLLoop 插件。

  • List item 。按 Alt+G 或单击“管理 Excel 加载项”旁边的前往 按钮。
  • List item 。单击“浏览”并提供 xlloop-0.3.2.xll 文件的路径。如果您下载了xlloop-0.3.2.zip,请将其解压,您将在/xlloop/bin中找到它
  • List item

希望有帮助。

编辑:

  • 启动 Excel。

  • 启动服务器(运行Main类)并测试公式。

我测试了以下 2 个(在 Excel 公式栏上输入它们并按/按 Enter 键),效果很好。 :)

  1. =FS("数学.sin", 3.14)
  2. =FS("数学.随机")

enter image description here enter image description here

关于java - 在 java 中使用 XLloop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23702980/

相关文章:

excel - 动态文件下载而不在服务器中保存文件

Java Sockets - 在没有输入流的情况下检测网络断开连接

java - 如何从接口(interface)实现中访问字段以进行测试

java - 仅将 https 与 spring cloud 微服务实例一起使用

sql - 我正在尝试在 Access VBA 中更新表中的某些字段

VBA宏: Formula is Based on a Column that changes locations

java - 如何从 Eclipse 中的现有源创建项目然后找到它?

java - Stax问题解析文档,其结束元素和开始元素在同一行

c# - 如何在 C# 中将 Excel 值转换为日期时间格式

vba - 两种算法的校正计算空行