Exception in thread main javalangIllegalStateException Cannot get a NUMERIC value from a STRING cell at orgapachepoixssfusermodelXSSFCelltypeMismatchXSSFCelljava987 at orgapachepoixssfusermodelXSSFCel
This exception is thrown when you are trying to retrieve a numeric value from a cell that contains a string value.
In your specific case, the exception is thrown at line 30 of the "ExcelToLineChart.java" file, where you are trying to call the getNumericCellValue() method on a cell that contains a string value.
To fix this issue, you need to make sure that you are retrieving the correct type of value from the cell. If the cell contains a string value, you should use the getStringCellValue() method instead of getNumericCellValue().
Here is an example of how to handle this situation:
Cell cell = row.getCell(columnIndex);
if (cell.getCellType() == CellType.STRING) {
String cellValue = cell.getStringCellValue();
// handle the string value
} else if (cell.getCellType() == CellType.NUMERIC) {
double cellValue = cell.getNumericCellValue();
// handle the numeric value
} else {
// handle other cell types if necessary
}
By checking the cell type before retrieving the value, you can avoid the IllegalStateException and handle different types of cell values appropriately
原文地址: http://www.cveoy.top/t/topic/hyUB 著作权归作者所有。请勿转载和采集!