我有一个 Java 代码,它通过aspose 库打开一个 excel 模板(它运行完美):
import com.aspose.cells.*;
import java.io.*;
public class test
{
public static void main(String[] args) throws Exception
{
System.setProperty("java.awt.headless", "true");
FileInputStream fstream = new FileInputStream("/home/vmlellis/Testes/aspose-cells/template.xlsx");
Workbook workbook = new Workbook(fstream);
workbook.save("final.xlsx");
}
}
在我使用RJB(Ruby Java Bridge)在 Ruby 上运行它之后:
require 'rjb'
#RJM Loading
JARS = Dir.glob('./jars/*.jar').join(':')
print JARS
Rjb::load(JARS, ['-Xmx512M'])
system = Rjb::import('java.lang.System')
file_input = Rjb::import('java.io.File')
file_input_stream = Rjb::import('java.io.FileInputStream')
workbook = Rjb::import('com.aspose.cells.Workbook')
system.setProperty("java.awt.headless", "true")
file_path = "/home/vmlellis/Testes/aspose-cells/template.xlsx"
file = file_input.new(file_path)
fin = file_input_stream.new(file)
wb = workbook.new(fin)
我收到此错误:
test.rb:57:in `new': Can't find file: java.io.FileInputStream@693a317a. (FileNotFoundException)
from aspose-test.rb:57:in `<main>'
为什么?我运行相同的代码......但在 Ruby 中不起作用!我该如何解决?
更新:
在文档中有初始化程序: Workbook(java.io.InputStreamstream)... 但它在 RJB 中不起作用。(这怎么可能?)