【问题标题】:IOException while trying to load an Excel file with Tablesaw (java)尝试使用 Tablesaw (java) 加载 Excel 文件时出现 IOException
【发布时间】:2020-01-02 05:00:32
【问题描述】:

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

我尝试了各种tablesaw 的功能和方法(读取/读取多重和XlsxReaderOptions 的各种构建器)。 xls 导入导出没有很好的文档记录(还),但我尝试重新使用我在 github 中看到的 jUnit 测试。

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

这里有没有人使用 tableaw 并且可以告诉我导入/导出 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)

感谢您提供的任何帮助!

【问题讨论】:

  • 未解决的编译问题 - 阅读消息。您的代码中的某些内容会抛出 IOException 而您不会 catch 它。

标签: java tablesaw


【解决方案1】:

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

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

【讨论】:

  • 谢谢,这是一个“NoTableFound”错误!显然,如果索引列(第一列)没有名称,tablesaw 无法导入表。我在我的 excel 文件中添加了一个索引名称,现在一切都很好。
猜你喜欢
  • 2019-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-28
  • 2014-11-19
  • 1970-01-01
  • 2020-07-09
  • 2023-04-09
相关资源
最近更新 更多