简体   繁体   中英

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

I am new in Java, and I am trying to use tablesaw ( https://jtablesaw.github.io/tablesaw/ ) to do some data visualization, but I get an IOException during the import of the file (see code below).

I have tried various functions and methods of tablesaw (read/readmultiple and various builder for the XlsxReaderOptions). The xls import export is not well documented (yet), but I tried to re-use the jUnit Test I saw in the github.

I have also checked the file path, and java.io.File find it. So I guess the mistake is in the code below.

Does anyone here use tablesaw and can show me the correct way to import/export excel file ? Or through another dataviz library ?

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;

    }

The error message :

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)

Thank you for any help you could provide !

You can try solved your issue with following import:

import java.io.IOException;

And handle your sub with add IOException like this:

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;

    }

Also put IOException in your main

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM