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);
}
}
}
編譯上述程序時發生以下錯誤。究竟是什麼原因?請修復。我是java的初學者。Apache POI中讀取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) {
如果他使用的Eclipse(或Netbeans的),應該有警告或自動導入選項:) – extraneon 2010-09-08 19:25:19
是的,謝謝...和wh找到這些類可以導入嗎? – LGAP 2010-09-08 19:26:27
在POI jars中,將其下載到POI項目頁面或通過maven。 – 2010-09-08 19:40:34