-2

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 !

  • *Unresolved compilation problem* - read the message. Something in your code throws and `IOException` and you do not `catch` it. – Scary Wombat Aug 29 '19 at 00:09

1 Answers1

1

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

frianH
  • 7,295
  • 6
  • 20
  • 45
  • Thanks, it was a "NoTableFound" error ! Apparently, tablesaw cannot import a table if the index column (the first column) don't have a name. I add a index name in my excel file, and everything is fine now. – Jérome Dejaegher Aug 29 '19 at 13:38