我尝试在 java 中使用 apache poi 读取 excel 文件,但是 Eclipse 没有编译代码。
public class ReadExcel {
public static void main(String[] args) throws IOException {
FileInputStream file = new FileInputStream(new File("C:\\Users\\XXXXXXXXXXXXXXXXal\\042012.xls"));
HSSFWorkbook wb = new HSSFWorkbook(file);
HSSFSheet sheet = wb.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
Row row = rowIterator().next(); \\ THIS LINE GETS UNDERLINED BY ECLIPSE!!!
Iterator<Cell> cellIterator = row.cellIterator();
while(cellIterator.hasNext()) {
Cell cell = cellIterator.next();
System.out.print(cell.getStringCellValue() + "\t\t");
}
}
file.close();
FileOutputStream out =
new FileOutputStream(new File("C:\\test.xls"));
wb.write(out);
out.close();
}
}
Eclipse 总是下划线Row row = rowIterator().next();
。我不知道为什么?我该如何改进它?