Ciao a tutti,
ho un problema con la lettura di un file excel con java da Eclipse.
Quando compilo il codice genera la seguente eccezione:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No exception of type BiffException can be thrown; an exception type must be a subclass of Throwable
at readerexcel.readexcel_2.read(readexcel_2.java:47)
at readerexcel.readexcel_2.main(readexcel_2.java:60)
Potete aiutarmi?
Grazie!
Il codice è il seguente:
codice HTML:
package readerexcel;
//http://www.vogella.com/tutorials/JavaExcel/article.html
import java.io.File;import java.io.IOException;
import jxl.Cell;import jxl.CellType;import jxl.Sheet;import jxl.Workbook;import jxl.read.biff.BiffException;
public class readexcel_2 {
private String inputFile;
public void setInputFile(String inputFile) { this.inputFile = inputFile; }
public void read() throws IOException { File inputWorkbook = new File(inputFile); Workbook w; try { w = Workbook.getWorkbook(inputWorkbook); // Get the first sheet Sheet sheet = w.getSheet(0); // Loop over first 10 column and lines
for (int j = 0; j < sheet.getColumns(); j++) { for (int i = 0; i < sheet.getRows(); i++) { Cell cell = sheet.getCell(j, i); CellType type = cell.getType(); if (type == CellType.LABEL) { System.out.println("I got a label " + cell.getContents()); }
if (type == CellType.NUMBER) { System.out.println("I got a number " + cell.getContents()); }
} } } catch (BiffException e) { e.printStackTrace(); } }
public static void main(String[] args) throws IOException { readexcel_2 test = new readexcel_2(); try { test.setInputFile("D:\\prova.xls"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } test.read(); }
}