views:

49

answers:

1
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import java.io.FileInputStream;
import java.lang.Iterable;

public class ReadExcel {
public static String fileToBeRead = "C:/Documents and Settings/Developer/Desktop/Anand   exmps/Anand.xls";
public static void main(String argv[]) {
try {
    HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(fileToBeRead));
    HSSFSheet sheet = workbook.getSheetAt(0);
    //HSSFRow row = sheet.getRow(0);
    //HSSFCell cell = row.getCell((short) 0);
    for (Row row : sheet) {
    for (Cell cell : row) {
        System.out.println("THE TOP LEFT CELL–> "+ cell.getRichStringCellValue());
    }
}

} catch (Exception e) {
    System.out.println("!! Bang !! xlRead() : " + e);
}   

}

}

The following error occurs when compiling the above program. What must be th reason? Please fix. Am a beginner in java.

 ReadExcel.java:16: cannot find symbol
 symbol  : class Row
 location: class ReadExcel
            for (Row row : sheet) {
                 ^
 ReadExcel.java:17: cannot find symbol
 symbol  : class Cell
 location: class ReadExcel
            for (Cell cell : row) {
+2  A: 

You forgot to import the Row and Cell classes.

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;

Resources :

Colin Hebert
And if he uses Eclipse (or Netbeans) there should have been a warning or an auto-import option :)
extraneon
yeah thanks... and where to find these classes to import?
LGAP
In POI jars, download it on the POI project page, or via maven.
Colin Hebert