本文介绍了CELL_TYPE_STRING 无法解析或不是字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
堆栈跟踪
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
CELL_TYPE_STRING cannot be resolved or is not a field
CELL_TYPE_NUMERIC cannot be resolved or is not a field
CELL_TYPE_BOOLEAN cannot be resolved or is not a field
at len.a.main(a.java:30)
代码
package len;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class a {
public static void main(String[] args) throws Exception{
ArrayList data =new ArrayList();
FileInputStream f =new FileInputStream("E:\\leadsuite.xlsx");
XSSFWorkbook wb=new XSSFWorkbook(f);
Sheet s=wb.getSheet("test steps");
Iterator itr=s.iterator();
while(itr.hasNext())
{
Row r=(Row) itr.next();
Iterator cellitr=r.cellIterator();
while(cellitr.hasNext())
{
Cell celldata=(Cell) cellitr.next();
switch(celldata.getCellType())
{
case Cell.CELL_TYPE_STRING:
data.add(celldata.getStringCellValue());
break;
case Cell.CELL_TYPE_NUMERIC:
data.add(celldata.getNumericCellValue());
break;
case Cell.CELL_TYPE_BOOLEAN:
data.add(celldata.getBooleanCellValue());
break;
}
}
}
}
}
推荐答案
enum
是 STRING
、NUMERIC
和 BOOLEAN
,删除 CELL_TYPE_
,它们是 CellType 枚举
The enum
s are STRING
, NUMERIC
and BOOLEAN
, drop the CELL_TYPE_
, and they are part of CellType enum
switch(celldata.getCellType()) {
case CellType.STRING:
data.add(celldata.getStringCellValue());
break;
case CellType.NUMERIC:
data.add(celldata.getNumericCellValue());
break;
case CellType.BOOLEAN:
data.add(celldata.getBooleanCellValue());
break;
}
这篇关于CELL_TYPE_STRING 无法解析或不是字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!