Ciao a tutti,
ho un problema in quanto non riesco a leggere il contenuto di un file excel (.xls) generato con Open Office da un codice java.
Utilizzo Eclipse versione 2.01.
Il codice apparentemente non presente errori ma quando lancio la compilazione viene emessa la seguente eccezione:
"Exception in thread "main" java.lang.NullPointerException at readerexcel.readexcel_1.main(readexcel_1.java:16)"
La riga 16 corrisponde al seguente codice: "Iterator<Row> rowIterator = sheet.iterator();"
Potete aiutarmi?
Grazie!
codice:
package readerexcel;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import jxl.Cell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class readexcel_1 {
public static void main(String[] args) {
try {
FileInputStream file = new FileInputStream(new File("D:\\prova.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
Iterator<jxl.Cell> cellIterator = Row.cellIterator();
while(rowIterator.hasNext() & cellIterator.hasNext()) {
Cell cell = cellIterator.next();
switch(cell.getCellType()) {
case Cell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue() + "\t\t");
break;
}
switch(cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t\t");
break;
}
switch(cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + "\t\t");
break;
}
}
System.out.println("");
file.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}