代码
... 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); } ...
根据上面的代码,我的输出如下:
身份证
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();
}
关于java apache poi(第 2 部分),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28755967/