CELL_TYPE_STRING cannot be resolved or is not a field

后端 未结 3 475
梦谈多话
梦谈多话 2021-02-04 15:05

Stack trace

Exception in thread \"main\" java.lang.Error: Unresolved compilation problems: 
CELL_TYPE_STRING cannot be resolved or is not a field
CELL_TYPE_N         


        
3条回答
  •  生来不讨喜
    2021-02-04 15:14

    Try this Code. It works... You just need to know poi api version and follow the new changes in poi api.

    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.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    
    
    public class A {
    
        public static void main(String[] args) throws Exception{
    
            ArrayList data = new ArrayList();
    
            FileInputStream file = new FileInputStream("F://LeadSuite.xlsx");
            XSSFWorkbook book = new XSSFWorkbook(file);
            XSSFSheet s = book.getSheet("TestSteps");
    
        Iterator itr = s.iterator();
        while (itr.hasNext()) {
            Row rowitr = (Row) itr.next();
            Iterator cellitr = rowitr.cellIterator();
            while(cellitr.hasNext()) {
                Cell celldata = (Cell) cellitr.next();
    
                switch(celldata.getCellType()) {
                case STRING:
                    data.add(celldata.getStringCellValue());
                    break;
                case NUMERIC:
                    data.add(celldata.getNumericCellValue());
                    break;
                case BOOLEAN:
                    data.add(celldata.getBooleanCellValue());
                    break;
                }
            }
        }
    
        for (int i=0;i

提交回复
热议问题