web-dev-qa-db-ja.com

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;
                }
            }

        }

    }

}
7
lenin kumam

enumsはSTRINGNUMERICおよびBOOLEANであり、CELL_TYPE_、そしてそれらは 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;
}
4
Guy