2010-09-08 5 views
2
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); 
} 

} 

} 

L'erreur suivante se produit lors de la compilation du programme ci-dessus. Quelle doit être la raison? S'il-vous-plaît, réparez. Suis un débutant en Java.Problème dans le POI Apache pour la lecture d'un fichier Excel

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) { 

Répondre

7

Vous avez oublié d'importer les classes et Cell.

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

Ressources:

+0

Et s'il utilise Eclipse (ou Netbeans) il devrait y avoir un avertissement ou une importation automatique option :) – extraneon

+0

ouais merci ... et wh Avant de trouver ces classes à importer? – LGAP

+0

Dans les fichiers POI, téléchargez-le sur la page du projet POI ou via maven. –

Questions connexes