...
while(rowIterator.hasNext()){
List<String> record = new ArrayList<String>();
row = (XSSFRow)rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while(cellIterator.hasNext()){
cell = cellIterator.next();
cell.setCellType(Cell.CELL_TYPE_STRING);
switch(cell.getCellType()){
case Cell.CELL_TYPE_STRING:
record.add(cell.getStringCellValue());
break;
case Cell.CELL_TYPE_NUMERIC:
record.add(Double.toString
(cell.getNumericCellValue()));
break;
}
}
readFile();
}
public void readFile(){
String ID = record.get(0);
System.out.println(ID);
}
...
从上面的代码中,我的输出如下所示:
ID
1个
2
3
我的预期输出应为:
1个
2
3
我的问题是如何从上述代码中的excel(ID)中删除第一行?
最佳答案
要跳过第一行:
while(rowIterator.hasNext()){
row = (XSSFRow)rowIterator.next();
if(row.getRowNum()==0) {
continue;
}
List<String> record = new ArrayList<String>();
Iterator<Cell> cellIterator = row.cellIterator();
...
readFile();
}