尝试使用 Tablesaw (java) 加载 Excel 文件时出现 IOException

IOException while trying to load an Excel file with Tablesaw (java)

我是 Java 的新手,我正在尝试使用 tablesaw (https://jtablesaw.github.io/tablesaw/) 进行一些数据可视化,但在导入文件期间出现 IOException(请参见下面的代码).

我尝试了 tablesaw 的各种功能和方法(read/readmultiple 以及 XlsxReaderOptions 的各种构建器)。 xls import export 没有很好的记录(还),但我尝试重新使用我在 github.

中看到的 jUnit 测试

我也检查了文件路径,java.io.File找到了。所以我猜错误在下面的代码中。

这里有人使用 tablesaw 并能告诉我 import/export excel 锉刀的正确方法吗?或者通过另一个 dataviz 库?

import tech.tablesaw.api.Table;
import tech.tablesaw.io.xlsx.*;

[...]

public class App 
{
    [...]

    private static Table getTable(String FileName)
    {
        XlsxReader reader = new XlsxReader();
        XlsxReadOptions options = XlsxReadOptions.builder(FileName).build();
        Table tab = reader.read(options);
    return tab;

    }

错误信息:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Unhandled exception type IOException

    at com.testPack.excelRun.App.getTable(App.java:30)
    at com.testPack.excelRun.App.main(App.java:22)

感谢您提供的任何帮助!

您可以尝试通过以下导入解决您的问题:

import java.io.IOException;

然后像这样添加 IOException 来处理你的潜艇:

private static Table getTable(String FileName)throws IOException{
        XlsxReader reader = new XlsxReader();
        XlsxReadOptions options = XlsxReadOptions.builder(FileName).build();
        Table tab = reader.read(options);
    return tab;

    }

同时将 IOException 放入您的 main