英文:
CELL_TYPE_NUMERIC cannot be resolved or is not a field
问题
Guys any help I can get here I will appreciate it. I keep getting this error message not sure what's going on. "both Cell type numeric and string cannot be resolved"
while (cellIterator.hasNext()){
    final Cell cell = cellIterator.next();
    switch (cellIndex)
    {
        case 0:
            if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                newStudent.studentId = (int)cell.getNumericCellValue();
                cellIndex++;
            }
            break;
        case 1:
            if(cell.getCellType() == Cell.CELL_TYPE_STRING) {
                newStudent.major = cell.getStringCellValue();
                cellIndex++;
            }else {
                newStudent.major = null;
            }
            break;
        case 2:
            if(cell.getCellType() == Cell.CELL_TYPE_STRING) {
                newStudent.gender = cell.getStringCellValue();
                cellIndex++;
            }else {
                newStudent.gender = null;
            }
            break;
    }
}
英文:
Guys any help I can get here I will appreciate it. I keep getting this error message not sure what's going on. "both Cell type numeric and string cannot be resolved"
          while (cellIterator.hasNext()){
                  final Cell cell = cellIterator.next();
                    switch (cellIndex)
                    {
                        case 0:
                        	if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                        		newStudent.studentId = (int)cell.getNumericCellValue();
                                cellIndex++;
                        	}
                            break;
                            
                        case 1:
                        	if(cell.getCellType() == Cell.CELL_TYPE_STRING) {
                        		newStudent.major = cell.getStringCellValue();
                                cellIndex++;
                        	}else {
                        		newStudent.major = null;
                        	}
                            break;
                            
                        case 2:
                        	if(cell.getCellType() == Cell.CELL_TYPE_STRING) {
                                newStudent.gender = cell.getStringCellValue();
                                cellIndex++;
                        	}else {
                        		newStudent.gender = null;
                        	}
                            break;
                    }
                    
                }
答案1
得分: 2
替代原有的代码:
CellType.STRING
CellType.NUMERIC
请参考链接:CellType
英文:
Instead of
Cell.CELL_TYPE_STRING
Cell.CELL_TYPE_NUMERIC
Use these:
CellType.STRING
CellType.NUMERIC
Reference link is CellType
答案2
得分: 1
我实际上对Apache POI不太熟悉,但根据这里的文档,看起来您可能需要使用CellType.NUMERIC代替Cell.CELL_TYPE_NUMERIC,以及使用CellType.STRING代替Cell.CELL_TYPE_STRING?
英文:
I'm not actually familiar with Apache POI, but from the documentation here, it looks like you might need to get CellType.NUMERIC instead of Cell.CELL_TYPE_NUMERIC, and CellType.STRING instead of Cell.CELL_TYPE_STRING?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论